How can I ssh directly to a particular directory?

前端 未结 12 2098
情话喂你
情话喂你 2020-12-07 07:03

I often have to login to one of several servers and go to one of several directories on those machines. Currently I do something of this sort:

localhost ~]$ ssh          


        
12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 07:55

    I know this has been answered ages ago but I found the question while trying to incorporate an ssh login in a bash script and once logged in run a few commands and log back out and continue with the bash script. The simplest way I found which hasnt been mentioned elsewhere because it is so trivial is to do this.

    #!/bin/bash
    
    sshpass -p "password" ssh user@server 'cd /path/to/dir;somecommand;someothercommand;exit;'
    

提交回复
热议问题