Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

share|improve this question

migrated from Oct 6 '11 at 11:29

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

2 Answers 2

up vote 5 down vote accepted

Try running:

ssh -t '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.