How to make SSH go directly to specific directory?

后端 未结 3 1912
孤城傲影
孤城傲影 2021-02-07 03:02

when you do an \"ssh second_machine\" you are able to connect to second_machine on your home directory

But usually i am working in my_machine in directory with very long

相关标签:
3条回答
  • 2021-02-07 03:36

    To make it permanent, use RemoteCommand in your ~/.ssh/config file, e.g.

    Host myhost
      HostName IP
      User ubuntu
      IdentityFile ~/.ssh/id_rsa
      RemoteCommand cd /path/to/directory; $SHELL -il
    

    Related:

    • SSH Config File Alias To Get To a Directory On Server
    • How can I automatically change directory on ssh login?
    • Run a remote command using ssh config file
    0 讨论(0)
  • 2021-02-07 03:48

    This should work for you

    ssh  -t second_machine "cd /very/long/path/to/directory/; bash"
    

    Assumes you're wanting to run bash, substitute for a different shell if required.

    0 讨论(0)
  • 2021-02-07 03:56

    You could do something like the one I'm using. Make an alias as the one below.

    alias ssh 'ssh -t \!* "cd $PWD; csh"'
    

    (here, csh could also be replaced by bash)

    This brings you directly to the 'current' path on the other machine. The usage would be like [$] ssh some machine However, I find that it works slow. So, I'm looking for an alternative.

    0 讨论(0)
提交回复
热议问题