一、任务要求
实现免密码登录,即密钥登录。
二、实验工具
X-shell 5
环境:Windows 7 x64
CentOS-6.5
三、ssh免密码登录的方法
1、ssh登录的方法
1.1 启动CentOS-6.5虚拟机,打开终端查看虚拟机IP地址;
![](https://img.haomeiwen.com/i12096430/99b4a467cc0870c2.png)
1.2 打开已安装好的X-shell工具,新建ssh用户登录,输入虚拟机名、IP地址,依次输入用户名、密码,点击确认登录(这里选择的是root用户登录);
![](https://img.haomeiwen.com/i12096430/d046d33e6bb40460.png)
![](https://img.haomeiwen.com/i12096430/04b91708c5234af2.png)
2、生成密钥,导入密钥;
2.1 使用X-shell 5生成密钥对;
![](https://img.haomeiwen.com/i12096430/8ae8340e32001baa.png)
![](https://img.haomeiwen.com/i12096430/037148dfc9ea82f1.png)
![](https://img.haomeiwen.com/i12096430/9bfa3b4cee418ca2.png)
![](https://img.haomeiwen.com/i12096430/f736c8bc071d96de.png)
![](https://img.haomeiwen.com/i12096430/a8740d3997b26d42.png)
2.2 对生成出来的密钥进行保存,便于后续Linux操作系统的密钥导入;
![](https://img.haomeiwen.com/i12096430/6460ca43a4fa8766.png)
![](https://img.haomeiwen.com/i12096430/b63615cab690a698.png)
3、配置ssh_config文件
3.1 找到ssh配置文件,从下列代码中可以看出,密钥配置文件为ssh_host_dsa_key;
[root@localhost ~]# cd /etc/ssh
[root@localhost ssh]# ls
moduli ssh_host_dsa_key ssh_host_key.pub
ssh_config ssh_host_dsa_key.pub ssh_host_rsa_key
sshd_config ssh_host_key ssh_host_rsa_key.pub
![](https://img.haomeiwen.com/i12096430/cac2f92a56fd0ac2.png)
![](https://img.haomeiwen.com/i12096430/7eea68c7200cc3f7.png)
3.2 找到密钥配置文件,进行密钥配置;
[root@localhost ~]# pwd
/root
[root@localhost ~]# ls -a
. .cshrc .gconfd .ICEauthority Public
.. .dbus .gnome2 install.log .pulse
anaconda-ks.cfg Desktop .gnote install.log.syslog .pulse-cookie
.bash_logout Documents .gnupg .local .ssh
.bash_profile Downloads .gstreamer-0.10 Music .tcshrc
.bashrc .esd_auth .gtk-bookmarks .nautilus Templates
.config .gconf .gvfs Pictures Videos
[root@localhost ~]# vi .ssh/authorized_keys
![](https://img.haomeiwen.com/i12096430/ed2a620b211ed118.png)
3.3 导入密钥,保存并退出,重启ssh服务;
![](https://img.haomeiwen.com/i12096430/2dddd26a878704c3.png)
[root@localhost ~]# service sshd restart
![](https://img.haomeiwen.com/i12096430/d92a1853a9acc1fa.png)
3.4 然后手动断开X-shell 5与虚拟机的连接,通过添加配置的密钥文件登录;
![](https://img.haomeiwen.com/i12096430/e7e3fb090395ae82.png)
![](https://img.haomeiwen.com/i12096430/d009a52e8310b3f4.png)
注意:
如果是多个用户的密钥登录的话,只需要在密钥配置文件中空一行,添加进去就可以实现多用户免密钥登录了。
网友评论