ssh免密码设置

服务器端sshd启动

/etc/init.d/sshd start

在本机器中的用户目录/root/.ssh/目录下执行下命令

ssh-keygen


提示输入密码,直接回车(没有密码)。

将生成两个文件,id_rsa和id_rsa.pub。

 
如下:

 

[root@localhost .ssh]# ssh-keygen
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: 
2d:c2:1e:59:43:61:b6:c3:89:1e:92:c4:92:a4:48:d9 
[email protected]

 

2、 将id_rsa.pub拷贝到远程机器,并且将id_rsa.pub的内容复杂到/root/.ssh/中,并重命名为authorized_keys(不能保留id_rsa.pub).

scp /root/.ssh/id_rsa.pub root@IP_ADD:/root/.ssh/authorized_keys

注意:目录.ssh和文件authorized_keys的权限必须是600(安全问题)

完成这些工作后,用户从“本地机器到远程机器的登录就不用密码了”(如ssh登陆及scp传输文件等)。


ssh/下面不要有,id_rsa.pub.把id_rsa.pub内容加入到你要登录的机器的authorized_keys 中就好,不要让对方机器id_rsa.pub放在本机的.ssh/下面.,因为本地id_rsa默认会和对方机器的id_rsa.pub验证配对,如果id_rsa.pub不存在才验证authorized_keys.

你可能感兴趣的:(职场,ssh,服务器端,休闲,sshd启动)