日期:2014-05-16  浏览次数:20706 次

使用Linux不需要密码scp ssh
一、为了使用scp的时候不需要输入密码,采用ssh另一种用密钥对来验证的方式 。
1、使用ssh-keygen 命令生成密钥。生成过程中,除了输入密码外,其他都选择默认的值:回车即可。不需要密码的话,输入密码时直接回车,那么密钥设置为空了,ssh或scp时默认用密钥,因为密钥为空,所以直接ssh
  [root@xxx root]# ssh-keygen -t rsa
   Generating public/private rsa key pair.
   Enter file in which to save the key (/root/.ssh/id_rsa):
   Created directory '/root/.ssh'.
   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:
   e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 root@xxx
   [root@xxx root]#
2、把这个密钥对中的公共密钥访问属性改为755,然后复制到备份的机器上去,并改名为 authorized_keys
  [root@xxx root]#chmod 755 /root/.ssh/id_rsa.pub
  [root@xxx root]# scp /root/.ssh/id_rsa.pub 192.168.1.92:/root/.ssh/authorized_keys
   root@xxx's password:
   id_rsa.pub                                    100%  218     3.2MB/s   00:00
   [root@xxx root]#
之后再用ssh scp sftp 访问那台机器时,就不用输入密码。这样可以利用shell进行自动文件传送了。