[英]Shell script to copy one directory from one server to another without asking for password
我想編寫一個shell腳本並將其放在cron中。 該Shell腳本每天一次將一個特定目錄從我的服務器復制到另一台服務器。 因此,我不希望它提示輸入密碼。 我可以在腳本中添加一些內容,以便它不會每天要求輸入密碼嗎?
您需要在Unix Box中輸入較少的密碼SSH登錄
下面的鏈接描述了如何設置較少的SSH登錄密碼
http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/
您可以使用FTP或NDM傳輸文件
通過這種方式,您可以實現您的要求。
使用以下腳本,我可以實現我提到的內容:
#!/ bin / bash com =“ sshpass -p Password0 scp arul@172.25.184.93:/home/arul/test.sh。” 評估$ com
您也可以為此使用RSA密鑰選項。 使用RSA密鑰,您可以在第一台服務器中授權第二台服務器。 這是一次操作。
ssh-copy-id -i ~/.ssh/id_rsa.pub [Your 2nd server IP]
例:-
[root@vasmon home]# ssh-copy-id -i ~/.ssh/id_rsa.pub xxx.xxx.xxx.xxx
root@xxx.xxx.xxx.xxx's password:
Now try logging into the machine, with "ssh 'xxx.xxx.xxx.xxx'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@vasmon home]#
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.