How to connect VSCode to Ubuntu (including detailed debugging for some incorrect default config)

table of contents

  • step-by-step guide
  • Common problems
    • Unable to connect to Ubuntu, resulting in no password prompt
    • Password is correct but permission is denied
    • Setting a password in Ubuntu

step-by-step guide

Step 1: Install the “Remote - SSH” Extension

Install the “Remote - SSH” extension from the Visual Studio Code marketplace.
在这里插入图片描述
Step 2: Open the Remote Explorer

After installing the extension, click the “Remote Explorer” icon located below the “Extensions” icon on the sidebar.
在这里插入图片描述
Step 3: Gather Your Server Information

On your Ubuntu server, run the following commands to obtain your HostName and User name:

For this example, let’s assume they are “172.25.231.252” and “root,” respectively.

whoami
ip a

Step 4: Open the SSH Config File

Click the settings icon to open the SSH Config file. This file is often located at “~/.ssh/config”.
在这里插入图片描述
Step 5: Add Your Server to the SSH Config File

Follow the format given below, replacing the placeholders with your server information obtained in Step 3.

Host myUbuntu
  HostName 172.25.231.252
  User root

Step 6: Connect to Your Server

Click the right-most icon to connect to your server in a new window.
在这里插入图片描述
Step 7: Select Your Server’s Platform

Select “Linux” as the platform.
在这里插入图片描述
Step 8: Enter Your Password

Enter your server’s password when prompted.
在这里插入图片描述
Step 9: Connection Successful

Once connected, you should see a welcome window indicating that the connection was successful.
How to connect VSCode to Ubuntu (including detailed debugging for some incorrect default config)_第1张图片

Common problems

Unable to connect to Ubuntu, resulting in no password prompt

To install the SSH server on Ubuntu, you can use the following command:

sudo apt update
sudo apt install openssh-server

Password is correct but permission is denied

In the sshd_config file content, the PermitRootLogin option is set to prohibit-password, which means that it does not allow root user login using password authentication. You need to change this option to yes and then restart the SSH service.

  1. Use a text editor to modify the sshd_config file:
sudo nano /etc/ssh/sshd_config
  1. Find the PermitRootLogin line and modify it to:
PermitRootLogin yes
  1. Save the file and exit the text editor.
  2. Restart the SSH service:
sudo service ssh restart

Setting a password in Ubuntu

To set a user password in Ubuntu, you can use the passwd command. Here are the steps to set a password:

  1. Open a terminal.

  2. Type the following command and then press Enter:

    passwd
    
  3. The system will prompt you to enter a new password, type the password you want to set, and then press Enter.

  4. The system will ask you to retype the new password for confirmation, retype the password you just entered, and then press Enter.

  5. If the two entered passwords match, the system will display passwd: password updated successfully, indicating that the password has been successfully set.

If you want to set a password for another user, you can use the following command:

sudo passwd username

And then follow the above steps to enter and confirm the password.

你可能感兴趣的:(编译原理笔记,vscode,ubuntu)