有些时候,我们在复制/移动文件到另一台机器时会用到scp,因为它比较安全。但如果每次都要输入密码,就比较烦了,尤其是在script里。不过,ssh有另一种用密钥对来验证的方
</p>
式。下面写出我生成密匙对的过程,供大家参考。
第一步:生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
1. [user1@rh user1]\$ ssh-keygen -t rsa
2. Generating public/private rsa key pair.
3. Enter file in which to save the key (/home/user1/.ssh/id\_rsa):
4. Created directory '/home/user1/.ssh'.
5. Enter passphrase (empty for no passphrase):
6. Enter same passphrase again:
7. Your identification has been saved in /home/user1/.ssh/id\_rsa.
8. Your public key has been saved in /home/user1/.ssh/id\_rsa.pub.
9. The key fingerprint is:
10. e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com
11. [user1@rh user1]\$
*复制代码*
1. [user1@rh user1]\$ chmod 755 \~/.ssh
2. [user1@rh user1]\$
*复制代码*
1. [user1@rh user1]\$ scp \~/.ssh/id\_rsa.pub
rh1:/home/user1/.ssh/authorized\_keys
2. user1@rh1's password:
3. id\_rsa.pub 100% 228 3.2MB/s 00:00
4. [user1@rh user1]\$
*复制代码*
了,用在script上更是方便。 </td> </tr> </tbody> </table> </div> |