Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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)


suku@ubuntu-vm:~$ cat 
print "Hello World\n";

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

suku@ubuntu-vm:~$ su - suku
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 and set command="/path/to/". 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


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.