Same directory - SSH

This is a discussion on Same directory - SSH ; Hi, 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Same directory

  1. Same directory

    Hi,

    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).

    Thanks.

  2. Re: Same directory

    On 2007-01-15 14:50:10 +0100, Xavier Décoret said:

    > Hi,
    >
    > 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).


    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 ssh.blah.com from my client
    client.blah.com, 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.

    --
    Sensei

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


  3. Re: Same directory

    Sensei wrote:
    > On 2007-01-15 14:50:10 +0100, Xavier Décoret said:
    >
    >> Hi,
    >>
    >> 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).

    >
    > 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 ssh.blah.com from my client client.blah.com,
    > 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.
    >


    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
    interested:

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

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

    In .ssh/config, put:
    SendEnv SSH_PWD

    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.

    X.

+ Reply to Thread