ssh私钥登录配置步骤

被连接服务器:

生成秘钥:
  • authorized_keys: 存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥
  • id_rsa: 生成的私钥文件
  • id_rsa.pub: 生成的公钥文件
  • know_hosts: 已知的主机公钥清单
[op@k8s-slave2 ~]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/op/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/op/.ssh/id_rsa.
Your public key has been saved in /home/op/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:LmZz2AOAPJIuqa8lsLNktOECRSGZfL9ZafC8tMS5TuQ op@k8s-slave2
The key's randomart image is:
+---[RSA 2048]----+
|ooo.             |
|o* o .           |
|o * o = o        |
|.+ . o %         |
|=+    @ S        |
|B.o  o E         |
|*=.   O =        |
|+*   o = .       |
|o..              |
+----[SHA256]-----+
[op@k8s-slave2 ~]$ ll .ssh/
total 16
-rw-rw-r-- 1 op op  395 Jan 24 16:00 authorized_keys
-rw------- 1 op op 1675 Jan 24 15:52 id_rsa
-rw-r--r-- 1 op op  395 Jan 24 15:52 id_rsa.pub
-rw-r--r-- 1 op op  174 Jan 24 15:54 known_hosts
配置生成的公钥:
cd .ssh/
cat id_rsa.pub >> authorized_keys
配置文件修改:
vim  /etc/ssh/sshd_config 
	# 免密码登录
	StrictModes no
	# 开启rsa验证
	RSAAuthentication yes
	# 是否使用公钥
	PubkeyAuthentication yes
	# 公钥保存位置
	AuthorizedKeysFile    .ssh/authorized_keys
	# 禁止使用密码登录
	PasswordAuthentication no
重启服务:
[root@k8s-slave2 ~]# systemctl restart sshd

客户端服务器:

配置被连接服务器的私钥:
根据指定私钥连接服务器:

[root@k8s-master /root]$ chmod 600 ./id_rsa
[root@k8s-master /root]$ ssh -i ./id_rsa op@10.10.80.176
Last login: Mon Jan 24 16:25:20 2022 from 10.10.80.178
[op@k8s-slave2 ~]$ 
posted @   咖啡馆  阅读(1098)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示