How to make a user that runs an interactive script on login and then logout?

349 Views Asked by At

I have a small elif script that has 4 options. I will need to make a user that has permissions to run just that script on login and when it finishes with the script to log him out.

I am trying to do it trough /etc/passwd like this: user:x:1003:1003::/home/user:script.sh

When already connected with root and then "su" to user, it executes the script. The issue is that the user cant connect trough putty and execute the script, which is the goal of what i am trying to do.

Any advise is welcome and appreciated.

Cheers,

2

There are 2 best solutions below

0
Kevin Boone On

Try giving the full path to script.sh in passwd. Even if this file is in the $PATH when you su to the user, it isn't necessarily in the $PATH in an SSH session. The SSH session might provide an environment that is different in other ways, too.

0
koyaanisqatsi On

Try a normal user with adduser and then edit two files in his home...

# .profile
logout

...and...

# .bash_logout
clear

When this user logs in ( with ssh/PuTTY ) then .profile logs him out and .bash_logout is executed too. So you can decide to do something at login or logout or twice.