VSCode use of Remote-SSH connection for remote Linux Development

Install and configure Remote-SSH

First open your VSCode, find Extensions, search Remote, Download Remote-Developoment plugin will automatically install other Remote plug-in, which will include Remote-SSH:
Remote-SSH
enter setup, search ssh, find and select the Remote-SSH Expansion of the ShowLoginTerminaloption because at the time of connection, the terminal will let you enter yes or password, etc.
Plug-in settings
then, you need to configure your Linux server address information, press CTRL+SHIFT+P, search ssh, find Open Configuration Filethe option
Search ssh
and then enter your address information:
Address information

Linux install OpenSSH-Server and Configuration

Ubuntu

// 先卸载
sudo apt-get remove openssh-server
// 安装
sudo apt-get install openssh-server

//重启sshd服务
sudo service ssh --full-restart
//自动启动
sudo systemctl enable ssh

CentOS

//安装
yum install -y openssl openssh-server

//重启sshd服务
systemctl restart sshd.service

//自动启动
systemctl enable sshd

Edit Profile

Backup configuration files

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

Edit Profile

sudo vim /etc/ssh/sshd_config

Configuration file, add the following configuration:
port can be customized
Configuration information
Configuration information
using a password
Configuration information
save and restart sshd server restart command has been given above.

SSH connection with password

Find your Linux server configuration:
connect to the server
Enter the password, and then press Enter:
enter password
then open the folder to begin writing code:
Open the folder
use CTRL + SHIFT + ~brings up the terminal, the terminal can operate in command, open the file you can write code.

Use key free password

Client configuration
to ensure that local Windows operating system has been installed ssh
generate SSH keys for:

ssh-keygen -t rsa -b 4096 

(-b 4096 rsa secret key generated to represent a length of 4096 bit) input after the instruction, let us specify the secret key to generate a file directory, can skip directly enter generated directory c:\user\WINDSUN\.sshgenerated under this directory : id-rsaand id-rsa.pubthe two documents, the first one is the private key file, the second is the public key file, the user name is your computer user name

Server-side configuration
detection ssh service is started

netstat -ntlp | grep ssh

Modify the configuration file

vim /etc/ssh/sshd_config

Here the most important thing is we need to PubkeyAuthenticationbe configured to yesallow the use of key authentication to log on the way.
Finally, the client public key id-rsa.pubupload files to the corresponding user .ssh root folder, the contents will enter the public key .ssh copied to authorized_keysfile

cp id_rsa.pub authorized_keys

Then set the appropriate file permissions

chmod 700 .ssh
chmod 600 .ssh/authorized_keys

The Remote-SSH VS plug-in configuration
settings vscode of Remote - SSH plug-in configuration file:

Host Aliyun
    HostName X.X.X.X
    User XXX
    IdentityFile  C:\Users\WINDSUN\.ssh\id_rsa

Problems encountered

If the message pipeline error, the problem may be

  1. ssh to your Linux server is configured with the question of whether to solve the problem by modifying the configuration of the test.
  2. Delete ".vscode-server" directory created on the server. This is a hidden directory created in your home directory (you can use the "ls -la" show all files I believe). Probably some incorrect data is cached in there, so delete the directory will make your situation more clean. After deleting, you can try to reconnect via remote-ssh on vscode.
  3. Problems encountered different operating system versions may also be different.

Guess you like

Origin www.cnblogs.com/WindSun/p/12142621.html