`
toty01
  • 浏览: 14087 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

解压缩命令tar和同步命令rsync

SSH 
阅读更多

tar命令用法:

 

  压缩: tar -czf 25.tar.gz  *.jpg

 

 解压缩:tar -xzf 25.tar.gz 

 

rsync用法

[本机:192.168.0.1] [客户端机器:192.168.0.2][用户名:test]


rsync -ravuq /home/test/ test@192.168.0.2:/home/test/

rsync -ravuq test@192.168.0.2:/home/test/ /home/test/

第一条rsync是从本地机器的/home/test/往192.168.0.2这台机器更新test目录下的内容
第二条rsync是从192.168.0.2这台机器更新本地机器的/home/test/目录下的内容。注意写法。

如想写成cron命令让机器自动运行。先把上面的两条命令写到sync.sh里,然后处理自动输入密码的问题。
如果cron命令写成:*/1 * * * * /home/test/sync.sh            #每分钟运行一次
那么在本机上:

[1]
cd /home/test
ssh-keygen -d
出现的询问,都敲回车(表示密码为空)
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:


然后出现:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
8f:f7:45:87:a0:11:a2:a7:ec:88:45:e8:33:21:35:3f root@www.andowson.com
表示你设置已经完成了。

在客户机上也运行[1] 命令

[2]
然后把本机生成的id_dsa.pub复制到客户机器上
scp /home/test/.ssh/id_dsa.pub 192.168.0.2:/home/test/.ssh/authorized_keys2

会出现:
The authenticity of host '192.168.0.2 (192.168.0.2)' can't be established.
RSA key fingerprint is e2:61:f0:78:31:21:72:ce:06:dd:da:02:f1:41:05:ec.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.2' (RSA) to the list of known hosts.
root@192.168.1.4's password:


id_dsa.pub                                                                        100% 611     0.6KB/s   00:00


显示以上提示说明copy已经完成了。
现在你可以在本机上用SSH连接客户机,就不会再提示输入密码了。
如果还是提示,那么到客户把authorized_keys2这文件权限设置为0777(一般不会出现这种情况)。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics