VS Code Remote SSH - How to Set Up Passwordless connection

Brainers Technology
3 Jan 202404:55

Summary

TLDRThis tutorial demonstrates how to set up an SSH connection in Visual Studio Code for remote development, allowing you to edit code on a remote machine as if it were local. It guides you through installing the Remote SSH extension, configuring a new SSH host, and connecting to it. The video also covers setting up passwordless connectivity using a private and public key pair, transferring the public key to the remote server, and configuring the server for key-based authentication. The result is a seamless, password-free remote development experience.

Takeaways

  • 💻 **Remote Development Setup**: The script explains how to set up Visual Studio Code (VS Code) for remote development using SSH.
  • 🔍 **Extensions Installation**: It guides to install the 'Remote SSH' extension from Microsoft for VS Code.
  • 🔗 **SSH Connection**: Demonstrates how to connect to a remote host by adding a new SSH host in VS Code.
  • 📁 **Config File Location**: Advises to select the path for the SSH config file, preferably in the user's home directory.
  • 🔑 **Password Prompt**: Describes the process of entering a password when prompted to connect to the remote server.
  • 🛠️ **Folder Access**: Explains how to open a folder on the remote server and enter the password again if prompted.
  • 🌐 **Immediate Code Changes**: Highlights that changes made in the VS Code editor are immediately reflected on a remote server, such as an EC2 instance.
  • 🔒 **Passwordless Connectivity**: Introduces the concept of setting up a passwordless connection using a private and public key pair.
  • 🔑 **Key Pair Creation**: Provides a step-by-step guide on creating a private and public key pair if one is not already available.
  • 📝 **Public Key Transfer**: Details the process of transferring the public key to the remote server and setting the correct permissions.
  • 🛡️ **SSH Configuration**: Explains how to edit the 'sshd_config' file to enable public key authentication and requires a restart of the SSH daemon.

Q & A

  • What is the main purpose of using Visual Studio Code (VS Code) with SSH?

    -The main purpose is to enable remote development by allowing users to edit code on a remote machine as if they were working on their local computer.

  • How can you set up an SSH connection in VS Code?

    -You can set up an SSH connection in VS Code by installing the 'Remote SSH' extension from Microsoft, then connecting to a host by adding a new SSH host with your user ID and hostname.

  • What is the recommended location for the SSH config file?

    -The recommended location for the SSH config file is in the user's home directory.

  • How do you connect to a remote host after adding it in VS Code?

    -You can connect to a remote host by clicking on the remote icon at the bottom left corner of the VS Code editor, choosing 'Connect to Host', and selecting the desired host name from the available options.

  • What is the necessity of setting up passwordless connectivity?

    -Setting up passwordless connectivity eliminates the need for password prompts, making the process of connecting to a remote server more efficient and user-friendly.

  • What are the requirements for a private key file in terms of security?

    -The private key file should stay on your local computer, and only the current user should have access to it. It's also important to mention the private key file name as the identity file in your configuration file.

  • How do you create a private and public key pair manually?

    -You can create a private and public key pair manually by opening the command prompt and entering 'SSH-keygen', then pressing enter a few times without typing anything.

  • What should you do with the public key file after creating it?

    -After creating the public key file, you should move it to the remote server using a method like WinSCP, and then rename it to 'authorized_keys' in the remote server's SSH folder.

  • What changes are required in the 'sshd_config' file for passwordless SSH to work?

    -In the 'sshd_config' file, you need to ensure that 'PubKeyAuthentication' is set to 'yes'. Any changes in this file require a restart of the SSH daemon with the command 'systemctl restart sshd'.

  • How can you ensure that only the owner has access to the 'authorized_keys' file on the server?

    -You can ensure that only the owner has access to the 'authorized_keys' file by setting the appropriate file permissions, ensuring that only the owner or the current user has read and write access to the file.

  • What is the benefit of using VS Code for remote development on an EC2 server?

    -The benefit of using VS Code for remote development on an EC2 server is that you can easily make changes to your website's code in the editor, and those changes are immediately reflected on the server without the need for manual updates.

Outlines

00:00

🔒 Setting Up SSH Connection in VS Code

This paragraph introduces the capability of Visual Studio Code (VS Code) to connect to a remote machine via SSH for code editing, as if the code were on a local machine. The speaker guides the viewer through the initial setup process, which includes opening VS Code, installing the 'Remote SSH' extension from Microsoft, and establishing a connection to a remote host by adding a new SSH host with user ID and hostname details. The viewer is also instructed on how to select the config file path and how to connect to the remote host for the first time, which requires entering a password.

🛠️ Exploring Passwordless SSH Connectivity

The second paragraph delves into setting up a passwordless SSH connection, which involves the use of a private and public key pair. The speaker explains that if the viewer already has a private key from a cloud provider, it can be used directly. If not, the process of generating both a private and public key manually is outlined, including using the command prompt to generate keys with 'SSH-keygen'. The private key should remain secure on the local computer, while the public key needs to be transferred to the remote server. The steps to rename the key file to 'authorized_keys' on the server and to ensure proper access permissions are detailed. Additionally, the speaker describes how to modify the 'sshd_config' file to enable public key authentication and to restart the SSH daemon for the changes to take effect, resulting in a passwordless connection experience.

Mindmap

Keywords

💡SSH

SSH stands for Secure Shell, a cryptographic network protocol for operating network services securely over an unsecured network. In the context of the video, SSH is used to connect to a remote machine securely, allowing the user to edit code as if they were working on a local computer. The script mentions setting up an SSH connection and transferring files securely between the local and remote environments.

💡Visual Studio Code (VSS Code)

Visual Studio Code is a popular source-code editor developed by Microsoft for Windows, Linux, and macOS. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. The video script describes using VSS Code to connect to a remote server via SSH and edit code remotely.

💡Remote Development

Remote development refers to the practice of coding on a remote machine rather than on a local machine. The script introduces the concept of using SSH to enable remote development within VSS Code, allowing developers to work on code hosted on a remote server as if it were on their local machine.

💡Passwordless Connectivity

Passwordless connectivity is a method of accessing systems without the need to enter a password each time. The video script discusses setting up SSH keys for passwordless authentication, which enhances security and convenience by eliminating the need for repeated password prompts.

💡Private Key

A private key is a secret value that is used to decrypt data that was encrypted with the corresponding public key. In the context of the video, the private key is part of an SSH key pair used for secure and passwordless access to a remote server. The script provides instructions on generating and using a private key for SSH connections.

💡Public Key

A public key is the counterpart to a private key in a key pair used in asymmetric cryptography. It can be freely distributed and is used to encrypt data that only the corresponding private key can decrypt. The script explains transferring the public key to the remote server to enable passwordless SSH access.

💡SSH Key Pair

An SSH key pair consists of a private key and a public key. The private key is kept secret on the user's local machine, while the public key is placed on the remote server. The script details the creation of an SSH key pair and the process of setting up passwordless SSH access using these keys.

💡WinSCP

WinSCP is a popular free and open-source FTP, SFTP, and SCP client for Windows that allows file transfers between local and remote computers. The script mentions using WinSCP as one of the methods to transfer the public key file to the remote server.

💡Authorized_keys

The authorized_keys file is a file on a remote server that contains the public keys of clients that are authorized to connect to the server without a password. The script describes renaming the public key file to 'authorized_keys' and placing it in the remote server's SSH directory for passwordless access.

💡SSH Daemon

The SSH daemon, or sshd, is the server program for SSH that listens for connections from SSH clients. The script mentions restarting the SSH daemon after making changes to the sshd_config file to enable public key authentication for passwordless access.

💡SSH Configuration File

The SSH configuration file, typically named config, is used to specify SSH client options. The script refers to editing this file to include the identity file (private key file name) and to specify the path for the SSH connection configuration.

Highlights

VS Code supports remote development via SSH, allowing code editing as if on a local machine.

Demonstrates how to set up an SSH connection for remote development in VS Code.

Installing the 'Remote SSH' extension from Microsoft is the first step.

Instructions on connecting to a host after adding a new SSH host in VS Code.

The importance of selecting the correct config file path for the SSH connection.

How to connect to a remote host using the Remote icon in VS Code.

The process of entering passwords for initial SSH connections.

Immediate reflection of code changes on a remote server-hosted website.

Introduction to setting up passwordless connectivity for SSH.

Explanation of the need for a private and public key pair for passwordless SSH.

Guidance on manually creating a private and public key if not provided by a cloud provider.

Instructions on transferring the public key to the remote server using WinSCP or similar methods.

Renaming the key file to 'authorized_keys' on the remote server.

Ensuring proper file permissions for the 'authorized_keys' file on the server.

Editing the 'sshd_config' file to enable public key authentication.

Restarting the SSH daemon to apply changes for passwordless connection.

Confirmation of a successful passwordless SSH connection setup.

Encouragement for viewers to like, subscribe, and comment for further engagement.

Transcripts

play00:00

[Music]

play00:03

welcome

play00:05

brainers VSS code is not just limited to

play00:08

your local development that's right you

play00:10

can simply open any folder on a remote

play00:12

machine using SSH and edit code as if it

play00:15

were right there on your local

play00:17

computer in the initial part of this

play00:19

video we'll show you how to set up an

play00:21

SSH connection right after that we'll

play00:25

explore the settings to achieve

play00:26

passwordless

play00:28

connectivity without further Ado let's

play00:30

get

play00:31

started please open your Visual Studio

play00:34

code

play00:35

application on the left side panel click

play00:38

on the extensions

play00:40

icon search and install remote SSH from

play00:45

Microsoft after installation click on

play00:47

the remote icon at the bottom left

play00:49

corner of the VSS code

play00:51

editor choose connect to

play00:54

host select add new SSH

play00:57

host type in your user ID followed by

play01:00

the at then the host name press

play01:04

enter please select the path for your

play01:06

config file preferably in the user's

play01:08

home

play01:09

directory the host is successfully added

play01:13

you can choose to connect from here

play01:15

alternatively for subsequent connections

play01:17

click on the remote icon located at the

play01:19

bottom left

play01:20

corner choose connect to host and select

play01:23

the host name from the available

play01:26

options enter the password when prompted

play01:28

and hit enter

play01:32

it's now connected to remote go ahead

play01:34

and open the

play01:41

folder if prompted please enter the

play01:43

password once

play01:46

again that's all you're now all set to

play01:50

commence your remote

play01:52

development this is my website hosted on

play01:54

an ec2 remote server to which I've just

play01:56

set up

play01:58

connection

play02:00

I can easily change the code in my vs

play02:02

code editor and the changes are

play02:04

reflected

play02:07

immediately all right let's now proceed

play02:10

to set up passwordless

play02:12

connectivity for passwordless connection

play02:15

we need a private and a public key

play02:17

pair in case you already got the private

play02:20

key received from your cloud provider

play02:22

you can use it directly in subsequent

play02:23

steps especially you no need to worry

play02:25

about serers side public key

play02:28

setup if you don't have the key I'll

play02:30

guide you on creating both private and a

play02:32

public key manually and right after that

play02:34

we transfer the public key to the remote

play02:37

server please open your command prompt

play02:39

and enter SSH hyphen key

play02:42

gen just hit the enter key a few times

play02:45

without typing

play02:49

anything navigate to the user's home

play02:52

directory specifically the SSH hidden

play02:55

folder you should see two new files

play02:57

created in this folder

play03:00

the private key file should stay on your

play03:02

local

play03:04

computer ensure that only the current

play03:06

user has access to this

play03:09

file additionally make sure to mention

play03:12

your private key file name as the

play03:14

identity file in your configuration

play03:18

file next move the public key file to

play03:21

the remote server using win SCP or any

play03:24

other preferred

play03:28

method

play03:31

copy or transfer the public key file

play03:33

from the local home directories. SSH

play03:35

folder to the SSH folder in the remote

play03:37

home

play03:43

directory rename the key file to

play03:45

authorized underscore keys on the

play03:49

server and ensure that only the owner or

play03:52

the current user has read and write

play03:53

access to this

play03:57

file log into the server an open sshd

play04:01

config file in the ETC SSH

play04:06

folder double check that Pub Key

play04:08

authentication is set to

play04:13

yes any changes in this file require an

play04:16

SSH demon restart with this pseudo

play04:18

system to restart sshd

play04:21

command we are all set to experience

play04:23

passwordless connection to the remote

play04:28

server

play04:34

great no more password prompts

play04:38

everything works as

play04:40

expected I hope this

play04:42

helpful please do like the video and

play04:45

subscribe to our

play04:46

Channel if you have any questions or

play04:48

thoughts please feel free to leave them

play04:50

in the comments section below thanks for

play04:53

watching

Rate This

5.0 / 5 (0 votes)

Related Tags
SSH SetupVS CodeRemote DevelopmentPasswordlessKey PairEC2 ServerSecure CodingSSH KeysRemote HostCoding Tutorial