linux ssh无密码登录
2012-07-12 15:00
204 查看
使用一种被称为"公私钥"认证的方式来进行ssh登录. "公私钥"认证方式简单的解释:首先在客户端上创建一对公私钥 (公钥文件:~/.ssh/id_rsa.pub; 私钥文件:~/.ssh/id_rsa)
然后把公钥放到服务器上(~/.ssh/authorized_keys), 自己保留好私钥.在使用ssh登录时,ssh程序会发送私钥去和服务器上的公钥做匹配.如果匹配成功就可以登录了。步骤如下:
1.在本地机器上生成密码对
[root@sg201 .ssh]# ssh-keygen -t rsa
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:
64:4e:53:ff:4b:f9:e4:34:6c:e0:45:5c:1f:20:c6:81 root@sg201
这时可以 看到在/root/.ssh下生成了私钥id_rsa和公钥id_rsa.pub这两个文件
[root@sg201 .ssh]# ls
id_rsa id_rsa.pub known_hosts
2.将公钥拷到服务器端/root/.ssh下并安装
[root@sg201 .ssh]# scp id_rsa.pub root@sg203:/root/.ssh
root@sg203's password:
id_rsa.pub 100% 392 0.4KB/s 00:00
登录服务器sg203进行如下操作
[root@sg203 .ssh]#cat id_rsa.pub
>> authorized_keys
[root@sg203 .ssh]# ls
authorized_keys id_rsa.pub known_hosts
[root@sg203 .ssh]# ls -l
total 12
-rw-r--r-- 1 root root 392 Jul 12 14:18 authorized_keys
-rw-r--r-- 1 root root 392 Jul 12 14:17 id_rsa.pub
-rw-r--r-- 1 root root 1183 Jul 10 16:29 known_hosts
[root@sg203 .ssh]# chmod 600 authorized_keys //权限的设置非常重要,因为不安全的设置安全设置,会让你不能使用RSA功能
3.在服务器sg203上开启ssh服务的Pubkey认证功能,操作方法如下
[root@sg203
ssh]#vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
然后重启ssh服务 service sshd restart
这时在sg201上就可以实现对sg203的无密码登录了
[root@sg201 ~]# ssh sg203
Last login: Thu Jul 12 14:45:25 2012 from sg201
[root@sg203 ~]#
待解决问题:这里用root帐号实现了ssh无密码登录,但我用新建的普通帐号hadoop却不行,不知是什么原因?
然后把公钥放到服务器上(~/.ssh/authorized_keys), 自己保留好私钥.在使用ssh登录时,ssh程序会发送私钥去和服务器上的公钥做匹配.如果匹配成功就可以登录了。步骤如下:
1.在本地机器上生成密码对
[root@sg201 .ssh]# ssh-keygen -t rsa
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:
64:4e:53:ff:4b:f9:e4:34:6c:e0:45:5c:1f:20:c6:81 root@sg201
这时可以 看到在/root/.ssh下生成了私钥id_rsa和公钥id_rsa.pub这两个文件
[root@sg201 .ssh]# ls
id_rsa id_rsa.pub known_hosts
2.将公钥拷到服务器端/root/.ssh下并安装
[root@sg201 .ssh]# scp id_rsa.pub root@sg203:/root/.ssh
root@sg203's password:
id_rsa.pub 100% 392 0.4KB/s 00:00
登录服务器sg203进行如下操作
[root@sg203 .ssh]#cat id_rsa.pub
>> authorized_keys
[root@sg203 .ssh]# ls
authorized_keys id_rsa.pub known_hosts
[root@sg203 .ssh]# ls -l
total 12
-rw-r--r-- 1 root root 392 Jul 12 14:18 authorized_keys
-rw-r--r-- 1 root root 392 Jul 12 14:17 id_rsa.pub
-rw-r--r-- 1 root root 1183 Jul 10 16:29 known_hosts
[root@sg203 .ssh]# chmod 600 authorized_keys //权限的设置非常重要,因为不安全的设置安全设置,会让你不能使用RSA功能
3.在服务器sg203上开启ssh服务的Pubkey认证功能,操作方法如下
[root@sg203
ssh]#vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
然后重启ssh服务 service sshd restart
这时在sg201上就可以实现对sg203的无密码登录了
[root@sg201 ~]# ssh sg203
Last login: Thu Jul 12 14:45:25 2012 from sg201
[root@sg203 ~]#
待解决问题:这里用root帐号实现了ssh无密码登录,但我用新建的普通帐号hadoop却不行,不知是什么原因?
相关文章推荐
- linux ssh 免密码登录
- Linux SSH免密码登录还提示密码 / ssh的免密码登陆不生效
- Linux SSH实现无密码远程登录
- linux ssh 不用密码自动登录的几种方法
- linux ssh 不需要登录密码,即可远程登录的配置
- Linux ssh登录 pshell以及各种ftp工具密码登录无密码登录(公钥)
- linux SSH免密码远程登录
- linux ssh 使用ssh-keygen设置SSH无密码登录
- linux ssh 不用密码自动登录的几种方法
- linux ssh免密码登录的原理
- Linux ssh安全设置,及免密码登录
- [置顶] Linux SSH免密码登录与拷贝文件(SCP)- 亲测
- linux ssh免密码登录
- linux ssh 不用密码自动登录的几种方法
- Linux SSH免密码登录与拷贝文件(SCP)
- linux ssh免密码登录
- Linux SSH免密码登录
- Linux SSH 无密码登录
- linux ssh免密码登录详解
- linux ssh 免密码登录