linux远程文件同步

1.先准备环境

sudo apt-get install ssh
2.建立凭证
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/ [email protected]:/opt/data/















郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。