2

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.

3 Answers 3

4

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.

1
  • +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, 2011 at 19:15
2

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.

2
  • 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, 2011 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.
    – user9517
    May 5, 2011 at 5:19
0

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .