Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I ssh into my freebsd I want to be automatically in another directory, and not my home directory.

I.e. instead of /users/home/john I want to be in /users/home/john/what/i/am/working/on

share|improve this question

3 Answers 3


ssh -t jdoe@example.com 'cd /tmp && exec /bin/sh'
share|improve this answer

So the simplest case of this is pretty easy. In your ~jdoe/.profile you can add:

if [ X$SSH_TTY != X ]; then
   cd /users/home/john/what/i/am/working/on
fi

If you're looking for the system to remember which directory you're in, per-terminal, and go back to the right one when you log back in on that terminal, that's more complex but still do-able with shell. Since $SSH_TTY is a filename, you can prepend "~/.mydirs/" to it, and use that filename to hold a copy of the CWD for the session of that terminal. It's more complex than that, but this is the general idea.

Hope this helps!
-pbr

share|improve this answer
ssh john@someplace:/path/to/wherever

notice the colon               ^

share|improve this answer
    
with which version of ssh is that possible? i always get 'could not resolve hostname xyz:/path ... and i dont see anything close to your suggestion in 'man ssh'. did you mix that up with 'scp'? –  akira Sep 13 '09 at 9:24

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.