配置密钥登录(免密)
密钥配置sshd_config配置文件说明
17 #Port 22 --- 修改远程服务端口
19 #ListenAddress 0.0.0.0 --- 监听端口(指定一块网卡接受ssh请求,其它地址访问拒绝;指定IP必须是本地网卡上存在的)
38 #PermitRootLogin yes --- 是否禁止root用户远程连接,:yes开启no关闭
39 #StrictModes yes --- 使用者的 ~.ssh/ 权限设错时,拒绝登陆:yes开启no关闭
43 #PubkeyAuthentication yes --- 公钥身份验证:yes开启no关闭
47 AuthorizedKeysFile .ssh/authorized_keys ---自制的公钥数据放置于用户家目录下的 .ssh/authorized_keys 内
64 #PermitEmptyPasswords no --- 是否允许远程用户使用空密码连接,默认no
79 GSSAPIAuthentication no --- 是否开启GASSAPI认证,比较古老,基本不用了 不用的时候关闭,会影响远程连接速度
115 UseDNS no --- 是否开启反向解析 建议关闭,影响远程连接速度
----------------------------ssh密钥登陆--------------------------------
vim /etc/ssh/sshd_config
PubkeyAuthentication yes #公钥身份验证:yes开启no关闭
PermitRootLogin yes #允许root登录:yes开启no关闭
PasswordAuthentication no #密码登录方式:yes开启no关闭
----------------------------------------------------------------------
配置密钥对
ssh-keyget -t dsa
在服务器上配置自制公钥文件authorized_keys
cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
设置权限
chmod 600 /root/.ssh/authorized_keys
重启服务
systemctl restart sshd
密钥保存到本地id_dsa
[root@yunwei .ssh]# ll
total 16
-rw------- 1 root root 601 May 9 21:23 authorized_keys ---授权认证文件
-rw------- 1 root root 668 May 9 13:49 id_dsa --- 密钥文件(保存到本地PC)
-rw-r--r-- 1 root root 601 May 9 13:49 id_dsa.pub --- 公钥文件
-rw-r--r-- 1 root root 685 May 9 14:31 known_hosts
-rw------- 1 root root 668 May 9 13:49 id_dsa --- 密钥文件(保存到本地PC后,建议从服务器侧删除)
------------------------非root用户密钥登陆--------------------------------
切换至普通用户
su - qin
ssh-keygen -t dsa
cd .ssh 查看生成的id_dsa(私钥) id_dsa.pub(公钥)
-rw------- 1 qin qin 668 Apr 24 10:36 id_dsa
-rw-r--r-- 1 qin qin 605 Apr 24 10:36 id_dsa.pub
cat /home/qin/.ssh/id_dsa.pub > /home/qin/.ssh/authorized_keys
ll
-rw------- 1 qin qin 605 Apr 24 10:38 authorized_keys
-rw------- 1 qin qin 668 Apr 24 10:36 id_dsa
-rw-r--r-- 1 qin qin 605 Apr 24 10:36 id_dsa.pub
chmod 600 /home/qin/.ssh/authorized_keys
id_dsa密钥保存至本地,或者删除,移走。
重启服务
systemctl restart sshd
文章评论