Limiting a user to a script upon login, nothing else.


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Limiting a user to a script upon login, nothing else.
# 1  
Old 01-07-2010
Tools Limiting a user to a script upon login, nothing else.

Hi there,

I have a Debian 5.0 server that my company uses for deployment testing. This server needs to be accessed by NOC people that have no NIX knowledge whatsoever.

I am creating a bash script for a menu-based command interface for the commands they need to run on their testing routines, but I wanted to know how can I force a user, upon login, to access this script (when he logins, this script is run) and nothing else (when he is finished, i.e., choose "X" for exit), the system log out the user.

Need help from the wise man Smilie
# 2  
Old 01-07-2010
You can create a log in hook, that when that specific user logs in, say via ssh a script runs. Then you can post an interactive script that runs with that log in hook...

example:
Code:
#!/bin/bash

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "Select an option please"
    echo "1 - Do something"
    echo "2 - Display something"
    echo "3 - third option"
    echo "4 - Print something"
    echo "5 - List some stuff"
    echo "6 - Display system information"
    echo "0 - exit and log out"
    echo " "
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
    1)  some command ;;
    2)  some command ;;
    3)  some command ;;
    4)  some command ;;
    5)  some command ;;
    6)  some command ;;
    0)  exit and log out ;;
*) echo "Please select a valid option"

done

That is just a quick and dirty example, and you would of course have to input the text and the related commands. I have used a similar script in the past to automate imaging PCs with Zen imaging from Novell. You can probably have init.d run this but I am a bit rusty on that.
# 3  
Old 01-07-2010
Quote:
Originally Posted by tlarkin
You can create a log in hook, that when that specific user logs in, say via ssh a script runs. Then you can post an interactive script that runs with that log in hook...

example:
Code:
#!/bin/bash

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "Select an option please"
    echo "1 - Do something"
    echo "2 - Display something"
    echo "3 - third option"
    echo "4 - Print something"
    echo "5 - List some stuff"
    echo "6 - Display system information"
    echo "0 - exit and log out"
    echo " "
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
    1)  some command ;;
    2)  some command ;;
    3)  some command ;;
    4)  some command ;;
    5)  some command ;;
    6)  some command ;;
    0)  exit and log out ;;
*) echo "Please select a valid option"

done

That is just a quick and dirty example, and you would of course have to input the text and the related commands. I have used a similar script in the past to automate imaging PCs with Zen imaging from Novell. You can probably have init.d run this but I am a bit rusty on that.
Yep, I mean, I have my script done on bash for the commands, but what I need help is how I hook it to the user login, and make sure that when the script exits, the user gets logged out...
# 4  
Old 01-07-2010
All of my *nix work in the past 5 years has been on the Apple platform so I am really loving launchd for this exact sort of thing, however, /etc/init.d should be able to do lots of similar things. So you would want to put your script in /etc/init.d/myscript but I am not quite sure how to make it user specific. In debain do they have any init.d run level stuff in a user's home folder?

The only other thing I can think of, is edit that user's bash profile (.profile, .bashrc, or whatever it is in Debian) to execute that script as part of the bash start up (or whatever shell you are using) that way when they ssh into the server it will auto execute at their user level.
# 5  
Old 01-07-2010
Replace the shell in /etc/passwd with the name of the script.
Make sure that the script contains all the required path statements etc.
# 6  
Old 01-07-2010
Quote:
Originally Posted by jgt
Replace the shell in /etc/passwd with the name of the script.
Depending on the system you may also need to add it to /etc/shells in order to allow it. But otherwise, this should work well for most UNIX systems -- the original script gets run directly, with no intermediate commands the user can interrupt, redirect, fold, spindle, or mutilate.

Note that it becomes your script's responsibility to set up its environment properly since there's no longer a login shell to do that for it -- it is the login shell Smilie

For further restriction yet your script could use a feature-restricted shell like /bin/rbash, which greatly reduces the shenanigans possible even if the user somehow manages to inject arbitrary input into your script. Or just make the user's login /bin/rbash and call your script from their bashrc files.

Last edited by Corona688; 01-07-2010 at 06:08 PM..
# 7  
Old 01-07-2010
Okay, I'll try some of this tomorrow but it sounds like what I am looking for. I have already on my script the exit commands to logout, but should the user break the script I still want him to be logged out or to return to the script, meaning I do not want him getting to the shell prompt by no means.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Login into another user from user inside script

now i have logged in username : ramesh in unix Now i have to created script file to login into another user and have run a command inside that user and after executing the command i have to exit from that user. Inside script, i have to login into su - ram along with password : haihow and have to... (4 Replies)
Discussion started by: rammm
4 Replies

2. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

3. UNIX for Dummies Questions & Answers

Limiting User mailbox size in /var/spool

How can one limit the size of user mailboxes in /var/spool/mail? (0 Replies)
Discussion started by: proactiveaditya
0 Replies

4. UNIX for Dummies Questions & Answers

User login monitoring script.

Hi guys, I'm need to write a script that runs an infinite loop to check users that login/out of a server. I'm just not sure about the syntax with while loops and whether or not you can include a nested if-statement? Cheers Spaulds (2 Replies)
Discussion started by: Spaulds
2 Replies

5. Shell Programming and Scripting

Running script from other user rather than login user

Hi, My requirement is that i am login from ROOT in a script but when any command is coming which is logging to sqlplus then i have to run it with normal user as only normal user have permission to connect to sqlplus . i tried making a script like this : #! /bin/ksh su -... (3 Replies)
Discussion started by: rawatds
3 Replies

6. Shell Programming and Scripting

limiting data inputs for the user

if my user has to enter the name of months to carry out a search how can I limit the input values to only the month names and nothing else? so far my input criteria for the user is this: i would like it so the user can only enter the months in the way i have stated. otherwise they would... (11 Replies)
Discussion started by: amatuer_lee_3
11 Replies

7. Shell Programming and Scripting

login to different user completely within the script

I am trying to write a script where I would login to a userid with id and password while staying completely within the script. I am doing this in order to edit a file where I change permissions. The objective is to allow one user only to edit a file. This is what I have now. cd $HOME/data ... (1 Reply)
Discussion started by: yakdiver
1 Replies

8. AIX

Limiting length of user in while creating user

Hi all, I am a newbe to aix 5.2. I want to specify the characters used by users while creating user in aix like specifying the length of the password should i use some sript for that if it is then please let me know how to do this if yes give me the link for the scripts. Thanks in advance ... (2 Replies)
Discussion started by: Satya Mishra
2 Replies

9. Shell Programming and Scripting

User Login Monitor Script

I need some help writing a script that I can run as a cron job. I want this script to be able find all the users that have logged on to this machine since the last time the script was run (plan to run daily at 11:30pm, so everyone who logged on that day) and email me who logged on, and when. ... (2 Replies)
Discussion started by: Drewser
2 Replies

10. UNIX for Dummies Questions & Answers

user login script question

hi all, what file(s) needs to be changed and in what way in order to do the following: when user A logs onto freebsd 4.8 automaticaly he needs to start up a script a made that executes: sets ltp0 in polling mode, executes tn5250 keyboard mapping starts tn5250 with the correct parameters. ... (2 Replies)
Discussion started by: termiEEE
2 Replies
Login or Register to Ask a Question