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

Is there a simple unix command to SSH into a folder? I'd like to make my aliases doing that extra step for me! Feeling dense.

Does this just not exist? ssh username@mydomain.com:/var/www/mysite

share|improve this question

migrated from stackoverflow.com Oct 6 '11 at 11:29

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

Try running:

ssh -t username@mydomain.com 'cd /var/www/mysite; $SHELL -il'

This will start a batch command with an attached tty. On the remote side, the batch command will change to the desired directory and start an interactive, login shell (using the shell from /etc/passwd on the remote site). After that things should work normally. You might even want to go as far as prepending env - TERM=$TERM DISPLAY=$DISPLAY.

share|improve this answer
that's a great solution. even allows for other options, like becoming another user (for example, a role account). – Tim Kennedy Oct 6 '11 at 14:54
BTW: ...thanks. – doublejosh Oct 27 '11 at 1:24

On the servers you connect to, you can add cd /var/www/mysite to the ~username/ssh/rc file . This would run on all ssh connections but not on normal login sessions.

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.