linux遠程文件同步
1.先準備環境
sudo apt-get install ssh2.建立憑證
ssh-keygen //注意,file與passphrase均無需輸入 Generating public/private rsa key pair. Enter file in which to save the key (/home/user1/.ssh/id_rsa): /home/user1/.ssh/id_rsa already exists. Overwrite (y/n)? user1@localhost:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/user1/.ssh/id_rsa): /home/user1/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user1/.ssh/id_rsa. Your public key has been saved in /home/user1/.ssh/id_rsa.pub. The key fingerprint is: ed:89:09:e0:5b:44:d0:78:e3:a2:a2:55:5c:15:43:e2 user1@localhost The key's randomart image is: +--[ RSA 2048]----+ | .+oo=. | | .o=. . | | ..+E. | | .+o. . | | o..o S . | |. o o . + . | |.o . o o | |. | | | +-----------------+
3.上傳憑證
scp ~/.ssh/id_rsa.pub user1@ip:/home/user1/.ssh/authorized_keys 若遠端報無此目錄異常,可先在遠端機器執行ssh-keygen命令產生,Copy成功信息: id_rsa.pub 100% 400 0.4KB/s 00:00
4.無密碼連接
ssh your-ip //若出現此信息: Agent admitted failure to sign using the key. //執行: ssh-add ~/.ssh/id_rsa //連接成功信息,注意命令提示已經切換到遠端: Last login: Sat Oct 25 09:57:29 2014 from 192.16.1.100 [user1@centos ~]$//設定其文件權限 chmod 600 ~/.ssh/authorized_keys
5.文件同步
rsync -a --delete/opt/data/ user1@192.16.1.100:/opt/data/
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!