欢迎访问我的个人博客网站:http://www.yanmin99.com/
一、准备工作
服务器
本机A: 192.168.1.1 服务器B: 192.168.1.2
二、ssh-key登录步骤
1、在本机A生成ssh公钥
2、在服务器B用户的 ~/.ssh/目录下执行:
//如果服务器B不存在.ssh目录, mkdir ~/.ssh //把本机A生成的id_rsa.pub中内容复制到authorized_keys中 vim ~/.ssh/authorized_keys
出于安全考虑,authorized_keys必须是600权限
3、在服务器B修改/etc/ssh/sshd_config,确认一下把SSHD的publickey验证模式打开
RSAAuthentication yes #启用RSA认证,默认为yes PubkeyAuthentication yes #启用公钥认证,默认为yes PasswordAuthentication no #不允许使用密码方式登陆 PermitRootLogin no #不允许root用户使用SSH登陆
修改/etc/ssh/sshd_config,需要切换root权限,修改需要重启sshd服务 service sshd restart
4、退出服务器B,再本机A登录服务器B
ssh root@xx.xx.xx.xx
三、禁用密码登陆
- 1、准备工作
- 确保至少有台机器是使用ssh登陆,建议2台以上,因为ssh-key重新生成或者机器重置系统都会生成新的key,到时候就不能登陆了。
2、编辑/etc/ssh/sshd_config
PasswordAuthentication no //禁止使用基于口令认证的方式登陆 PubkeyAuthentication yes //允许使用基于密钥认证的方式登陆
3、重启sshd服务
//centos /etc/init.d/sshd restart //ubuntu //如果ssh重启没有效果,就重启系统 /etc/init.d/ssh restart shutdown -r now