VS Code Remote SSH - How to Set Up Passwordless connection
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
🔒 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
💡Visual Studio Code (VSS Code)
💡Remote Development
💡Passwordless Connectivity
💡Private Key
💡Public Key
💡SSH Key Pair
💡WinSCP
💡Authorized_keys
💡SSH Daemon
💡SSH Configuration File
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
[Music]
welcome
brainers VSS code is not just limited to
your local development that's right you
can simply open any folder on a remote
machine using SSH and edit code as if it
were right there on your local
computer in the initial part of this
video we'll show you how to set up an
SSH connection right after that we'll
explore the settings to achieve
passwordless
connectivity without further Ado let's
get
started please open your Visual Studio
code
application on the left side panel click
on the extensions
icon search and install remote SSH from
Microsoft after installation click on
the remote icon at the bottom left
corner of the VSS code
editor choose connect to
host select add new SSH
host type in your user ID followed by
the at then the host name press
enter please select the path for your
config file preferably in the user's
home
directory the host is successfully added
you can choose to connect from here
alternatively for subsequent connections
click on the remote icon located at the
bottom left
corner choose connect to host and select
the host name from the available
options enter the password when prompted
and hit enter
it's now connected to remote go ahead
and open the
folder if prompted please enter the
password once
again that's all you're now all set to
commence your remote
development this is my website hosted on
an ec2 remote server to which I've just
set up
connection
I can easily change the code in my vs
code editor and the changes are
reflected
immediately all right let's now proceed
to set up passwordless
connectivity for passwordless connection
we need a private and a public key
pair in case you already got the private
key received from your cloud provider
you can use it directly in subsequent
steps especially you no need to worry
about serers side public key
setup if you don't have the key I'll
guide you on creating both private and a
public key manually and right after that
we transfer the public key to the remote
server please open your command prompt
and enter SSH hyphen key
gen just hit the enter key a few times
without typing
anything navigate to the user's home
directory specifically the SSH hidden
folder you should see two new files
created in this folder
the private key file should stay on your
local
computer ensure that only the current
user has access to this
file additionally make sure to mention
your private key file name as the
identity file in your configuration
file next move the public key file to
the remote server using win SCP or any
other preferred
method
copy or transfer the public key file
from the local home directories. SSH
folder to the SSH folder in the remote
home
directory rename the key file to
authorized underscore keys on the
server and ensure that only the owner or
the current user has read and write
access to this
file log into the server an open sshd
config file in the ETC SSH
folder double check that Pub Key
authentication is set to
yes any changes in this file require an
SSH demon restart with this pseudo
system to restart sshd
command we are all set to experience
passwordless connection to the remote
server
great no more password prompts
everything works as
expected I hope this
helpful please do like the video and
subscribe to our
Channel if you have any questions or
thoughts please feel free to leave them
in the comments section below thanks for
watching
関連動画をさらに表示
SSH Keys
How To Configure SSH On A Cisco Device | Secure Connection
2 | How to Install a Local Server for PHP | 2023 | Learn PHP Full Course for Beginners
Self Host 101 - Set up and Secure Your Own Server
Day-15 | Ansible Zero to Hero | #ansible #devops
Hardening Access to Your Server | Linux Security Tutorial
5.0 / 5 (0 votes)