VScode connects to Ubuntu server remotely

VScode connects to Ubuntu server remotely

本文记录了在VScode连接Ubuntu虚拟机并修改虚拟机内文件时遇到的问题及解决方法,如有不对的地方欢迎大家指正

提示:以下是本篇文章正文内容,下面案例可供参考

1. VScode connects to the server

The first step: VScode installs the plug-in and configures:

1. Search for remote-ssh in VScode and install:
insert image description here

2. Configure the config file:
where host is the host name, which can be set casually; the following are the ip address and user name, which are set according to the server to be connected. The virtual machine can enter "ifconfig" to see the server ip.

insert image description here

insert image description here

Step 2: Remote server configuration:

1. Install the SSH service on the server:
sudo apt-get install openssh-server

2. Check if SSH is installed:
ssh -V

3. After the installation is complete, you can use the following command to check whether the SSH service has been started. If there is sshd information in the query result, it means that the SSH service has been started normally.
sudo ps -e | grep ssh

4. If there is no ssh information, we can start the SSH service:
sudo service ssh start

5. After starting, we need to configure the ssh service so that we can log in remotely.
The configuration file of the SSH service is under /etc/ssh/sshd_config. We can open this configuration file for modification:
Modification 1: Change the "PermitRootLogin without" in the configuration file Add a "#" in front of -password, and comment it out.
Modification 2: Add a sentence "PermitRootLogin yes"

6. Save and exit. Restart the ssh service:
/etc/init.d/ssh restart

Step 3: VScode remote connection:

After configuring the config of VScode in the first step, you can make a remote connection.
insert image description here
Then enter the password to successfully connect.

2. Problems encountered and solutions

1. Unable to modify the hosts file

After using VScode to change the file in the remote host, when saving, it prompts that the file permission is not enough to save.

> The code is as follows (example):
Enter the folder where the file is located, enter the command ls -ll and
the output is:
insert image description here
It is found that the owner and group members of this file are both root, preceded by -rw-r–r–, and only read-only permission is available at this time. The following is enough to increase the permissions of the file so that everyone can read and write this file:
chmod 666 111111.py

At this time, enter "ls -ll" again to query the permissions of the file, and find that the previous one has changed to -rw-rw-rw-.
Then when you enter VSCode for file editing, you can find it.

Guess you like

Origin blog.csdn.net/strive0_0/article/details/124967746