简体   繁体   English

远程Shell脚本

[英]Shell script remotely

I have one script running on server and doing some job on other server I have many scp commands and ssh commands, this is why each time I have to enter the remote server password at each remote command. 我在服务器上运行一个脚本,并在其他服务器上执行某些工作,所以我有许多scp命令和ssh命令,这就是为什么每次必须在每个远程命令中输入远程服务器密码时的原因。 is there any way to establish ssh connection between the servers so I type the remote password only once? 有什么方法可以在服务器之间建立ssh连接,所以我只键入一次远程密码? thanks 谢谢

I would suggest to setup an ssh config together with ssh keys. 我建议与SSH密钥一起设置SSH 配置 In a nutshell the config will hold an alias for one or more remote servers. 简而言之,配置将为一台或多台远程服务器保留一个别名。

ssh remote_server1
ssh remote server2

While your config file will look something like this: 虽然您的配置文件将如下所示:

Host remote_server1
Hostname 192.168.1.12
user elmo
IdentityFile ~/.ssh/keys/remote.key
...

If an ssh config file is not for you (although I can highly recommend it), you can use sshpass as well. 如果不适合您使用ssh配置文件(尽管我强烈推荐),您也可以使用sshpass

sshpass -p 't@uyM59bQ' ssh username@server.example.com

Do note that the above does expose your password. 请注意,以上内容确实公开了您的密码。 If someone else has access to your account, the history command will show the code snippet above. 如果其他人有权访问您的帐户, history命令将在上方显示代码段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM