Linux SSH密钥创建

1.创建密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ssh-keygen -t rsa -b 4096
#执行创建命令,-b参数为指定密钥长度
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
#设置密钥密码,可以直接回车跳过
Enter same passphrase again:
#确认密码,可以直接回车跳过
Your identification has been saved in /home/user/.ssh/id_rsa.
#公钥
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
#私钥
The key fingerprint is:
SHA256:B25KhIK5xNfR3j7SBi52+e2Z+t0K7Ouhg3IzRqxyuEE pi@Debian
The key's randomart image is:
+---[RSA 4096]----+
| .. |
|.o .... |
|oo....o o |
|.... . + o |
|. E + S . |
| . + X *. |
| .o * = o+ |
| o.+ * oo.* . |
| .+ + oo*O.o.. |
+----[SHA256]-----+

2.生成authorized_keys

1
2
3
cd
cd .ssh/
cat id_rsa.pub >> authorized_keys

3.修改权限

1.修改权限

1
chmod 700 .ssh
1
chmod 600 .ssh/authorized_keys

4.修改ssh的配置文件

1
vi /etc/ssh/sshd_config
1
2
3
4
5
6
7
8
9
10
11
# 允许root登录,但是禁止root密码登录
PermitRootLogin prohibit-password

# 通过RSA认证
RSAAuthentication yes

# 允许pubKey(id_rsa.pub)登录
PubkeyAuthentication yes

#使用密码 no为不使用密码
PasswordAuthentication yes

Linux SSH密钥创建
https://kuan.pages.dev/article/6d2a3284.html
作者
IKun
发布于
2023年1月25日
许可协议