Same directory

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I cannot find the following information: how do I ssh on a remote login
so that on the remote machine, I end up in a given directory (e.g. the
current directory if I ssh on a machine that mounts the same home dir).


Re: Same directory

Quoted text here. Click to load it

By /default/ using ssh you *log in*, so you create a session for a user
on the remote machine.

If I ssh with ``sensei'' on from my client, and on my client I am logged as ``sensei'', the two
homonymous users have nothing in common. You always end up in the user
home directory.


Research (n.): a discovery already published by a chinese guy one month
               before you, copying a russian who did it in the 60s.

Re: Same directory

Sensei wrote:
Quoted text here. Click to load it

You are right. Since you can use ssh to run a command remotely, I was
hopping that you could run a command, like cd, and *then* stay logged to
type interactive command.

Finally, I came up with a kind-of-solution that I post here for those

In your .login, put:
if ($?SSH_PWD) then
        cd $SSH_PWD

In your .tcshrc (adapt if you use bash)
alias ssh 'env SSH_PWD=$PWD ssh'

In .ssh/config, put:

In the /etc/ssh/sshd_config of the client, put:
AcceptEnv SSH_PWD
(and be sure to restart the sshd service [eg: service sshd restart]

This last point makes the solution really a hack: you need to be root on
the client. In my case, where I want to log within a parc of machines in
my building, that mount the same homedirs, it was quite easy to
propagate this setup on the whole parc.  This way, when I am working on
my machine in a directory and want to log onto another machine
(typically the one with the dongle that let me run some special app), I
stay in the same dir.


Site Timeline