Ssh – No shell and launch application on login

bashopenvmssshunix-shell

I am working on migrating an application from OpenVMS to RedHat Linux 6. The application is a green screen terminal application. The users will log into Linux via SSH and the application should automatically start but they should never have access to the shell. Once the application closes or crashes it should automatically log them out. What is the best way to approach this?

I've tried creating a new user with the following command.

useradd -s /sbin/nologin test

I then added ftp & to the users .bash_profile in the hope it would open the ftp console immediately and then once they quit it would log them out. However upon authentication on SSH the session is killed. Any ideas?

Best Answer

The "green screen" application I've supported for the past 12 years accomplishes this via a modified .bash_profile and a wrapper script to start the application.

enter image description here

After the systems are built and service users created, we modify the default .bash_profile in the /etc/skel directory. This ensures that new users created on the system pick up the login settings.

Let's call the application "peach"

Inside the .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

The actual "run-peach" wrapper script will look like:

#!/bin/bash

set -e

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

The set -e and trap are important here.

Related Topic