PDA

View Full Version : SSH login directory



cashew
09-17-2005, 05:17 PM
Hi there,

I've recently moved from westhost 1.0 to 2.0. When I login via SSH my current directory is my home directory ( ~ ) as expected. However, when I run commands on my server using SSH as a remote shell, they run in the root ( / ) directory.

For clarity:

homemachine > ssh mydomain@mydomain.com
westhostserver > pwd
/home/mydomain

That is as expected.

homemachine > ssh mydomain@mydomain.com pwd
/

This is not expected, the command I executed (pwd in this example) ran in the root directory rather than the home directory.

This didn't use to happen on westhost 1.0, on westhost 1.0 my commands also executed in the home directory.

Does anyone know how to fix it so my commands once more execute in the home directory?

Thanks in advance

Cheddarmakerman
09-19-2005, 08:09 AM
In your /.bashrc file:

export HOME=/home/mydomain
cd $HOME
remember... /.bashrc NOT ~/.bashrc like you might expect.

cashew
09-19-2005, 03:52 PM
Thanks for the tip, I see now how the vuser thing works, tricking the home directory, however it didn't solve the problem. My /.bashrc already contained the commands you suggsted. The /.bashrc appears to be only executed if you login through ssh, not if you use ssh to execute a command on the server.

It is possible to edit /home/.ssh/rc to contain commands that will be executed before the login shell or command is executed, however, changing directory in that rc doesn't work, I assume it is changed back immediately after the rc finishes. I also tried setting HOME to the correct value using /.ssh/environment, but that didn't work either.

I assume if you execute a 'pwd' command using ssh as described in the original post that it also outputs '/' instead of $HOME for you too?

Any other suggestions?!

Cheddarmakerman
09-19-2005, 04:15 PM
The /.bashrc appears to be only executed if you login through ssh, not if you use ssh to execute a command on the server.
oh... I think you are right. I guess that you could always do something like this:

ssh user@domain.com 'cd /home/usr; command'

cashew
09-19-2005, 04:40 PM
oh... I think you are right. I guess that you could always do something like this:

ssh user@domain.com 'cd /home/usr; command'

Yeah that's true, I've got that one down as my last resort, as it involves rejigging my previously working backup, ftp and cvs scripts. If no one has any further hints I may well have to do that :(

Thanks for trying though.

allyn
09-20-2005, 01:58 PM
i had to bite the bullet and modify all of my backup and upload scripts when i moved to westhost 2. i wasn't happy about the directory change either but never found a way around it.