Can I ssh somewhere, run some commands, and then leave myself a prompt?

前端 未结 5 1418
予麋鹿
予麋鹿 2020-11-29 04:56

I find myself needing to log into various servers, set environment variables, and then work interactively.

e.g.

$ ssh anvil
jla@anvil$ export V=hello         


        
5条回答
  •  没有蜡笔的小新
    2020-11-29 05:53

    Probably the simplest thing is:

    $ ssh -t host 'cmd1; cmd2; sh -i'
    

    If you want to set variables, do:

    $ ssh -t host 'cmd1; cmd2; FOO=hello sh -i'
    

    Note that this is a terrible hack, and you would be much better off putting your desired initial commands in a script and doing:

    $ scp setup host:~
    $ ssh host
    host$ . setup
    

提交回复
热议问题