Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to make a SSH login for someone on my box. But when they login I want it to auto load a perl script and for them ONLY to be aloud to see / use that perl script.

I only know how to use useradd command, I do not know how to set perms ect.

I don't know how to explain this in more detail. But any help would be aswsome!!!

share|improve this question

2 Answers 2

Create a new user for this 'someone' and put your perl script in his home directory and then make an entry in his .bash_profile for invoking the perl script.

FYI : The ~/.bash_profile gets executed during every login shell (eg: ssh,switch user etc)

Example:

suku@ubuntu-vm:~$ cat hello.pl 
#!/usr/bin/perl
print "Hello World\n";

suku@ubuntu-vm:~$ cat .bash_profile 
perl ~/hello.pl

suku@ubuntu-vm:~$ su - suku
Password: 
Hello World

[EDIT] useradd -m username will create a user with his home directory as /home/username

If you really want to limit this user's scope only to read and execute your perl script, you need to set immutable attribute for his home directory

Setting immutable attribute:

sudo chattr +i /home/username

Removing immutable attribute:

sudo chattr -i /home/username

If you do so, this user can't touch anything new in his home directory. But he can execute/read your perl script

share|improve this answer
    
Hmm, I only know how to make a account with useradd command, I don't know how to link the account to a home directory nor do what you just said lol. –  Tom Doobies Jan 5 '13 at 2:37
    
I use centos version 5. –  Tom Doobies Jan 5 '13 at 2:44
    
Okay, I made the .bash_profile and I cannot beleive how simple that was lol. Now how can I limit him to ONLY stay in his home directory? because with control+c you can break and go out of bounds. –  Tom Doobies Jan 5 '13 at 3:05
    
Read the update in the answer –  Suku Jan 5 '13 at 3:33
    
It would be better to use exec to call the secondary program so that the shell is replaced with the program - that way once the program exits (either naturally or by an interrupt) the SSH session will be closed. –  James O'Gorman Jan 7 '13 at 9:21

The best way to do this is to use the authorized_keys file. You can restrict a user to run just one command with one Key. So, if a user login with one specified key, he will be able to run just one command.

The setup is to use the command ="" directive, specified in the authorized_keys file. The syntax for this looks like:

command ="command",  KEY

This tells SSH to run command and then exit. It effectively limits your ability to run commands on the remote server.

In order to run multiple commands securely, you have a few options. First, consider calling a script instead of command. For example, run top, df -k and hostname from a shell script named myscript.sh and set command="/path/to/myscript.sh". Second, if you need to run multiple commands at different times during the day to same host, you could create another key for your user.

For auto-loading feature, you can simply put it in .bash_profile, present in their home directory, as described by Suku.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.