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

When logged in to the server I don't want to cd /path/to/directory every time I connect to the server. I'm connecting via Putty. I've tried to execute a command once connected to change the directory, but it just closes Putty.

share|improve this question
up vote 4 down vote accepted

You can probably just append cd /path/to/directory to your .bashrc.

Alternatively if you're the admin of the server you may want to change your home directory to point there.

Edit: as @smintz says this is probably not a good idea if you don't own the directory. I've seen it done though, so I thought I'd point it out.

share|improve this answer
+1 for .bashrc, do not change home directory path, it will create a lot of problems with permissions and missing configuration files in home. – smintz May 4 '11 at 19:15

You can put cd /path/to/directory in your .bash_profile if you want it to happen only when you log in. If you want it to occur whenever you open a shell then you should use your .bashrc.

If you want to do it from PuTTY then get KiTTY which is a fork of PuTTY. Under the Data section of session configuration you can define a command to run at login.

share|improve this answer
I assume that KiTTY, exactly like PuTTY will close the window right after login, this caused by the nature of ssh, if you adding a command, the session will be closed right after the execution file finish. – smintz May 4 '11 at 21:25
@smintz: Nope, instead of assuming - like me you could easily have checked. It runs the command an then drops you to the prompt. – Iain May 5 '11 at 5:19

Do you want to run "cd ..." every time you log into that server or just when you use putty? If you just want to do this when you use putty, you can have putty set an environment variable and then check for that when you log in, but your ssh server must turn on AcceptEnv (assuming openssh)

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.