Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 would like to know if there is a way to specify what script to run (on the remote machine) at login. I'm logging into a Debian box with key-pair authentiation (no password needed). The script needed to run will be different, so I don't want to put it into ~/.bashrc, I want to specify it on the command line when I login, something like:

ssh username@ip script_on_remote.sh

share|improve this question

migrated from serverfault.com Apr 22 '13 at 13:15

This question came from our site for system and network administrators.

up vote 5 down vote accepted

Your example is pretty much how you'd do it. You can specify the script using it's full path if it's not accessible on the $PATH.

# if scripts on the $PATH
ssh username@ip script_on_remote.sh

# if it's not on the path
ssh username@ip /path/to/my/script_on_remote.sh

# if it's including spaces
ssh username@ip "/path to my/script_on_remote.sh"
share|improve this answer

Specifying the command on the command line will work. You may have to put in the full path of the command.

share|improve this answer

Your Answer


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