Lizhiyu
Lizhiyu's Blog

Lizhiyu's Blog

Remote Development using SSH on VS Code

Lizhiyu's photo
Lizhiyu
Mar 23, 2022

I have to say amazing after remote ssh on vs code. Debugging and preview remote on vs code is what I want for a long time. What a pity, it's too late to meet 不.

The Visual Studio Code Remote - SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code's feature set. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem.

Step1: Generate an SSH Key

execute: ssh-keygen

output:

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/user-name/.ssh/id_rsa): input the absolute path here.

Enter passphrase (empty for no passphrase):

Then, you got two file in your .ssh directory. Something like tutorial and tutorial.pub.

Step2: Copy the key to a server

Once an SSH key has been created, the ssh-copy-id command can be used to install it as an authorized key on the server. Once the key has been authorized for SSH, it grants access to the server without a password.

ssh-copy-id -i ~/.ssh/mykey user@host

Only the public key is copied to the server. The private key should never be copied to another machine.

Step3: Install VS Code extension

Download Remote-SSH

Step4:Create a config file

Host aws-ec2 
    HostName 188.188.1.8
    User ubuntu
    IdentityFile /Users/user-name/.ssh/file-name
- Host (aws-ec2) is just a name that will appear in VS Code. It can be any name.
- HostName is the servers host or IP.
- User is the Ubuntu username.
- IdentityFile is the path to the private key.

Step5:Configure in VS Code

  • Show all command to find remote-ssh Screen Shot 2022-03-23 at 15.55.57.png
  • Excute the Connect to Host

Screen Shot 2022-03-23 at 15.58.21.png

  • Configure SSH Hosts Screen Shot 2022-03-23 at 16.00.48.png

  • Setting configure path Screen Shot 2022-03-23 at 16.00.29.png

Screen Shot 2022-03-23 at 16.01.03.png

  • Excute the Connect to Host Select one you have configired.

Screen Shot 2022-03-23 at 16.03.19.png

Then, connected. Screen Shot 2022-03-23 at 16.04.06.png

Enjoy remote developing, debug and preview locally with the power of VS Code.

Thanks for your reading.

Have a good day.

Did you find this article valuable?

Support Lizhiyu by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors