码迷,mamicode.com
首页 > 系统相关 > 详细

linux远程文件同步

时间:2014-10-25 12:04:08      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   os   ar   java   for   sp   文件   

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远程文件同步

标签:style   color   io   os   ar   java   for   sp   文件   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!