实现scp传送不需要密码
来源:互联网 发布:淘宝手机版卖家中心 编辑:程序博客网 时间:2024/06/06 12:31
由于昨天要从A服务器想B服务器传送一个200G的数据库文件,所以打算晚上进行后台自动传送,但是scp这个命令执行时需要密码,导致nohup无法实现,所以决定写个脚本让其后台执行,但是输入密码这个环节必须去掉,所以想到了建立双机信任这个功能:
我们可以通过在A主机上生成公钥,然后放到B主机上,以后则在A主机需要ssh连接B主机就不需要密码了!
Linux/Unix双机建立信任教程
一 需要建立信任关系的2台主机都执行生成密钥
输入ssh-keygen -t rsa之后全部默认回车,这样就会在/root/.ssh下生成密钥文件
[root@platform_iks .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
63:9f:6e:8b:98:49:e3:a2:bc:49:8a:a1:d5:1b:03:3a root@platform_iks.internal.lietou.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| |
| . S |
| . o . o . |
|E o + o o |
|oB ..* = o. |
|+ =o..= ..o. |
+-----------------+
二 查看~/.ssh生成密钥的文件
[root@platform_iks .ssh]# ll
总用量 12
-rw-------. 1 root root 1675 9月 14 10:46 id_rsa
-rw-r--r--. 1 root root 419 9月 14 10:46 id_rsa.pub
-rw-r--r--. 1 root root 2360 9月 10 15:53 known_hosts
三 建立信任关系
1 A对B建立信任关系
[root@platform_iks .ssh]# scp -r id_rsa.pub 10.10.10.17:/root/.ssh/authorized_keys
root@10.10.10.17's password:
id_rsa.pub 100% 419 0.4KB/s 00:00
[root@platform_iks .ssh]#
即:把A的公钥(id_rsa.pub)拷贝到B,并修改id_rsa.pub 为 authorized_keys
此时需要输入密码(之前未建立信任关系),建立了客户端到服务端的信任关系后,客户端就可以不用再输入密码,就可以从服务端拷贝数据
四 在B机器上执行同样的操作
[root@localhost .ssh]# ssh-keygen --help
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ^C
[root@localhost .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
b3:b4:62:1b:5a:fb:8c:70:50:6c:22:aa:11:2e:01:23 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|E |
|o. . |
|o . . + |
|.+ . + |
|+. . S |
|o. . . + |
|. . * o |
| * B |
| . +.o |
+-----------------+
[root@localhost .ssh]# ll
总用量 16
-rw-r--r--. 1 root root 419 9月 14 10:52 authorized_keys
-rw-------. 1 root root 1671 9月 14 10:54 id_rsa
-rw-r--r--. 1 root root 408 9月 14 10:54 id_rsa.pub
-rw-r--r--. 1 root root 2357 9月 12 14:35 known_hosts
[root@localhost .ssh]# scp -r id_rsa.pub 10.10.10.20:/root/.ssh/authorized_keys
root@10.10.10.20's password:
id_rsa.pub
四 测试
[root@localhost ~]# scp -r a 10.10.10.20:/root/
a 100% 0 0.0KB/s 00:00
[root@localhost ~]# ls
双机之间拷贝文件,不再需要输入密码了
双机信任关系已经建立!
- 实现scp传送不需要密码
- CentOS下实现SCP免输密码传送文件
- 使用ssh、scp不需要密码
- scp ssh 不需要密码登录
- scp不输密码,自动传送方法
- scp 远程拷贝不需要输入密码
- ssh/scp不需要输入密码的方法
- SCP不需要输入密码的sh脚本
- linux 机器 scp 不需要密码设置
- ssh 用 scp 命令 后台传输文件 ,不需要输入密码
- Linux scp复制文件,不需要输入密码的技巧
- ubuntu下scp批量拷贝文件不需要输入密码
- SCP命令拷贝到另一台服务器不需要输入密码
- Linux scp复制文件,不需要输入密码的技巧
- Linux scp复制文件,不需要输入密码的技巧
- scp批量自动远程复制脚本不需要输入密码
- scp命令来实现LINUX间传送文件
- 实现执行scp命令时不需要输入用户密码
- 构建赫夫曼树,并输出节点编码
- mvc的优点
- Mysql关联表查询的索引
- 有一天,柏拉图问老师......
- iPhone文件读写
- 实现scp传送不需要密码
- nginx源码分析(4)-方法(1)
- ASP.NET缓存 之 Web服务器缓存
- linux下解压命令大全
- eclipse python插件
- 风尘中,忘了捡拾那日女子留下的胭脂
- nginx源码分析(5)-方法(2)
- 【UI设计】UI参考网站
- HDU 2054 字符串 比较两个数大小,忽略整数前面的0和小数最后的0