login时没有shell和启动应用程序

我正在将应用程序从OpenVMS迁移到RedHat Linux 6.该应用程序是一个绿色屏幕terminal应用程序。 用户将通过SSHlogin到Linux,应用程序应该自动启动,但不应该有权访问该shell。 一旦应用程序closures或崩溃,它应该自动登出。 什么是最好的方法来处理这个?

我试着用下面的命令创build一个新的用户。

useradd -s /sbin/nologin test 

然后我把ftp&添加到用户.bash_profile中,希望能够立即打开ftp控制台,然后一旦退出,就会将其注销。 然而,在SSH上进行身份validation后,会话被终止。 有任何想法吗?

对这组用户和ForceCommand使用Match块来强制执行OpenVMS程序,使用一个包装脚本来使用它自己的exit来注销用户。

 ForceCommand Forces the execution of the command specified by ForceCommand, ignoring any command supplied by the client and ~/.ssh/rc if present. The command is invoked by using the user's login shell with the -c option. This applies to shell, command, or subsystem execution. It is most useful inside a Match block. The command originally supplied by the client is available in the SSH_ORIGINAL_COMMAND environment variable. Specifying a command of “internal-sftp” will force the use of an in-process sftp server that requires no support files when used with ChrootDirectory. 

由于这不会是一个loginshell,所以不需要注销,只需退出:

 Match Group oldies ForceCommand /usr/local/bin/wrapper 

示例包装脚本可能如下所示:

 # cat /usr/local/bin/wrapper #!/usr/bin/env bash dialog --title "Message" --yesno "Wrapper around your OpenVMS program" 6 25 exit 0 

这对于ssh访问是有效的。

您也可以强制从/etc/passwd执行相同的包装脚本:

 bob:x:1100:1100:Sponge Bob:/home/bob:/usr/local/bin/wrapper 

并从login控制台具有相同的function。

你为什么不把应用程序设置为用户的shell? 这意味着它是login时唯一运行的东西,并且(除了应用程序本身的某种访问)他们不能做任何事情。

过去12年来我所支持的“绿屏”应用程序通过修改.bash_profile和封装脚本来启动应用程序。

在这里输入图像说明

在系统build立和服务用户创build之后,我们修改/etc/skel目录中的默认.bash_profile 。 这可确保在系统上创build的新用户获取login设置。

我们称之为“桃子”

在.bash_profile里面,

 # Source any peach-specific variables . /etc/default/peach # Set up the search paths: PATH=$PATH:. # Set up the shell environment: set +u trap "echo 'logout'" 0 # Run the peach application or start script: /opt/peach/bin/run-peach 

实际的“run-peach”包装器脚本将如下所示:

 #!/bin/bash set -e <blah blah> # do stuff, set MOAR variables /opt/peach/bin/peach # run application binary 

set -etrap在这里很重要 。