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.

There is a remote host, where I'd like to run a specific script every time I connect to it via ssh. Where should I put the file to be run automatically?

share|improve this question

3 Answers 3

From the ssh man page:

~/.ssh/rc
         Commands in this file are executed by ssh
         when the user logs in, just before the user's
         shell (or command) is started.  See the
         sshd(8) manual page for more information.
share|improve this answer

Add it to the authorized-keys file for the key you are connecting with (setup a private key auth as well) and use the command field in the file, for more info do a "man authorized-keys" to see what else you can setup.

share|improve this answer

In the remote server?

ssh my-remote-host /usr/local/bin/my-remote-script

You can limit the ssh to run only one command with a specific key also, thus limiting the key usage. See http://pkeck.myweb.uga.edu/ssh/ for examples

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.