分享

ssh, scp 免输入密码访问

 忧郁_小刚 2012-10-28



经常在不同linux机器之间互相scp拷文件,每次总是要输入密码才可行。

通过ssh-keygen生成公钥,在两台机器之间互相建立信任通道即可。

假设本地机器client,远程机器为server。

1. 生成rsa keygen

[winter@client winter] $ ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/winter/.ssh/id_rsa): <Enter>
Enter passphrase (empty for no passphrase): <Enter>
Enter same passphrase again: <Enter>
Your identification has been saved in /home/winter/.ssh/id_rsa.
Your public key has been saved in /home/winter/.ssh/id_rsa.pub.
The key fingerprint is:
33:d4:7b:9c:87:04:cf:14:40:22:6d:c7:15:78:97:6a winter@client

直接上面公钥和私钥存放地址可以直接回车,私钥密码可以直接回车,也可以输入。

2. 查看.ssh目录下了多私钥和公钥文件

[winter@client winter] $ ls .ssh/
id_rsa  id_rsa.pub  known_hosts

3. 拷贝公钥到目标机器上,并改名成authorized_keys

[winter@client winter] $ scp .ssh/id_rsa.pub winter@192.168.0.110:/home/winter/.ssh/authorized_keys
The authenticity of host '192.168.0.110(192.168.0.110)' can't be established.
RSA key fingerprint is 5b:78:e8:e9:dc:d8:db:bd:f7:66:44:e6:3b:ce:f2:79.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.110' (RSA) to the list of known hosts.
winter@192.168.0.110's password: <Enter>
id_rsa.pub                                                                     100%  221     1.2MB/s   00:00

首次scp命令时候还是会提示输入密码,还有是否继续链接的提示,以后

4. 测试ssh进入

[winter@client winter] $ ssh 192.168.0.110

5. ok,搞定!

[winter@server winter] # it's ok!




[winter@client winter] $ ssh 192.168.0.110

5. ok,搞定!

[winter@server winter] # it's ok!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多