首页 > 系统服务 > 详细

linux远程文件同步

时间:2014-10-25 12:02:05      阅读:339      评论:0      收藏:0      [点我收藏+]

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/ user1@192.16.1.100:/opt/data/















linux远程文件同步

原文:http://my.oschina.net/raydchang/blog/337173

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!