您的位置:首页 > 运维架构 > Linux

Linux下SSH远程不用密码登陆

2014-09-27 10:52 399 查看
SSH登录命令

ssh root@10.168.10.1

这时候会让你输入密码

命令格式为:ssh 用户@主机IP

不用密码登陆的过程如下:

原理是在远程主机上添加本地生成公钥,这样会自动验证,就不需要输入密码了

1 本地SSH-keygen

[root@localhost ~]# 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:
90:b0:f3:63:1b:9e:95:42:7f:15:95:7b:19:2a:29:a0 root@localhost.localdomain


然后我们到该路径下可以看到生成的文件

[root@localhost ~]# cd ~/.ssh/
[root@localhost .ssh]# ls
id_rsa  id_rsa.pub
2 拷贝到远程的主机~/.ssh/下

这里可以用命令scp直接拷贝

[root@localhost ~]# scp ~/.ssh/id_rsa.pub root@10.168.10.1:~/.ssh/id_rsa.pub
3 登录远程主机
[root@localhost ~]# cd ~/.ssh
[root@localhost ~]# cat id_rsa.pub >> authorized_keys
4 降低权限

[root@localhost ~]# cd ..
[root@localhost ~]# chmod -R 0600 ~/.ssh


这样,再用ssh登陆就不用输入密码了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: