vscode通过ssh连接linux
客户端vscode安装拓展 Remote-SSH
配置config
注意 User
txt
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host ubuntu22
HostName 192.168.157.128
Port 22
User raopan
IdentityFile C:\Users\raopan\.ssh\id_rsa
Host CentOS7
HostName 192.168.157.101
Port 22
User root
IdentityFile C:\Users\raopan\.ssh\id_rsa1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
服务器centos开启ssh
修改 /etc/ssh/sshd_config 文件以调整配置
bash
# 大概是35行开始,将以下配置改为 yes
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
RSAAuthentication yes
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
重启ssh服务
bash
systemctl status sshd.service
# 会显示下面内容,注意第6行是Active: active (running)就行
# ● sshd.service - OpenSSH server daemon
# Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
# Active: active (running) since 三 2024-10-09 09:56:55 CST; 12h ago
# Docs: man:sshd(8)
# man:sshd_config(5)
# Main PID: 972 (sshd)
# Tasks: 1
# Memory: 4.7M
# CGroup: /system.slice/sshd.service
# └─972 /usr/sbin/sshd -D1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
配置ssh服务开机自启动
bash
systemctl enable sshd.service1
免密登录
在windows 终端生成公钥id_rsa.pub 和私钥
bash
ssh-keygen -t rsa1
bash
# 一直回车,生成在 C:\Users\raopan\.ssh 目录下
D:\App\System>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\raopan/.ssh/id_rsa):
C:\Users\raopan/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\raopan/.ssh/id_rsa
Your public key has been saved in C:\Users\raopan/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:kxXPPHC2AOa/xup6/5v3J/whMCcn5qe1gVUQWzJkXD0 raopan@DESKTOP-SHG4ECH
The key's randomart image is:
+---[RSA 3072]----+
| o.+ =Boo.|
| o X.o*E.|
| . . *. ..|
| oo.X |
| +o * . |
| .o +.B o|
| .+o..o++ ++|
+----[SHA256]-----+1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
将公钥复制到服务器上
在 linux root/.ssh目录下,生成authorized_keys文件
bash
touch ~/.ssh/authorized_keys1
将 id_rsa.pub 复制到 linux root/.ssh 目录下,copy到authorized_keys文件
bash
cat id_rsa.pub >> authorized_keys1
将文件权限修改 600
bash
chmod 600 .ssh/authorized_keys1