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

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

From the ssh man page:

         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 for examples

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.