Start SSH connection in PuTTY, run a command, and leave the session active

可紊 提交于 2019-12-19 08:01:05

问题


I want to run a few shell commands every time I SSH to a server via PuTTY. I'm connecting to a production web server managed by someone else, and I don't want to store my own scripts there.

I see the option Connection > SSH > Remote Command, but if I put my initialization commands there, after starting the session, it closes immediately after the commands execute. How can I run the Remote Command, and then keep the session open so I can continue using it?


回答1:


The SSH session closes (and PuTTY with it) as soon as the command finishes. By default the "command" is a shell. As you have overridden this default "command" and yet you want to run the shell nevertheless, you have to explicitly execute the shell yourself:

my-command ; /bin/bash

See also Executing a specific command on the server.




回答2:


One option to go is set up your putty remote command like this:

ls > dir.ls & /bin/bash

In this example command you want to run is "ls > dir.ls" what creates file dir.ls with content of directory listing.

And as you want to leave shell open you can add aditional command "/bin/bash" or any other shell of your choice.



来源:https://stackoverflow.com/questions/28779243/start-ssh-connection-in-putty-run-a-command-and-leave-the-session-active

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!