简体   繁体   中英

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. is there any way to establish ssh connection between the servers so I type the remote password only once? thanks

I would suggest to setup an ssh config together with ssh keys. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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