VSCode connects to remote server and docker

1 Install VSCode

1.1 download

1. Official website download address https://code.visualstudio.com/
insert image description here
2. Select the corresponding version of your own system to download:
insert image description here

1.2 Installation

1. Double-click the downloaded exe to install

insert image description here
2. Browse the installation path

insert image description here
3. Add to the start menu, here is the default

insert image description here
4. Check as shown in the figure

insert image description here
Note: After checking " Register Code as a supported file type editor ", many text formats will be changed to open with VSCode

5. Confirm the information and install
insert image description here

2 Install OpenSSH

1. Run PowerShell as an administrator
2. Input: Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
not installed as shown in the figure below
insert image description here
3. Skip this step if it is installed, and execute if it is not installed:

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

insert image description here
After the installation is complete, as shown in the figure below:
insert image description here
4. Verify, input: ssh
as shown in the figure below, the installation is successful:
insert image description here

3 VSCode configuration ssh

1. Click the extension in the left toolbar, search for "ssh", and select the first one to install (here already installed)

insert image description here

2. Click the "Settings" button in the lower left corner, and then click "Settings":
insert image description here
3. Find "Show Login Terminal" and check this option
insert image description here

4 VSCode connects to remote server

1. Click "Remote" in the left toolbar to view the remote connection, and then click **+**
insert image description here

2. Click the Add button, enter the address of the remote server, account number and ip to modify by yourself, press Enter to save the
Click the button next to the server displayed under "SSH TARGETS" to connect
input information to the configuration file
insert image description here
3, right-click to select, as shown below,
insert image description here
select the system to be used to
insert image description here
enter the password, and then succeed Connect to a remote server.

4. You can choose the files of the remote server to operate

5 VSCode connects to the container in the remote server docker

1、

docker run -it --name 容器名 -v 服务器文件目录:容器目录  -p vcscode连接端口:22 镜像id /bin/bash

2. After entering the container, download and install openssh.
The first method:

yum update && yum install -y --no-install-recommends openssh-server

The second method:

yum update
yum install openssh-server
yum install openssh-client

Ubuntu changes yum to apt-get
without reporting an error during the installation process. If there is an sshd_config configuration file in the /etc/ssh directory, the installation is successful

3. Modify the configuration file

vim /etc/ssh/sshd_config

Uncomment the " # " in the following line
Port 22
ListenAddress 0.0.0.0
ListenAddress::

PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes

4. Set the root password for VScode login
command: passwd and
enter it twice as prompted

5. Restart the ssh service
ubuntu: service ssh restart (use the command service ssh status to view the status)
centos: /etc/init.d/ssh restart (/etc/init.d/ssh status)
or /usr/sbin/sshd -D &

insert image description here
If the above error occurs, you need to perform the following settings in order:

ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' 
ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''

Then restart the ssh service, the process number will be returned if the startup is successful
insert image description here

Check whether the ssh service is enabled:ps -e | grep sshd
insert image description here

Check whether port 22 is enabled for listening:

yum install net-tools
netstat -an | grep 22

insert image description here
6. Then connect according to the way of connecting to the server

Host 名称任意
	HostName 服务器ip地址
	Port 输入上面设置的vscode连接的端口 
	User root

insert image description here

Guess you like

Origin blog.csdn.net/weixin_50008473/article/details/126369567