SSH Guide
What is SSH?
SSH Explained
SSH (Secure Shell) is a protocol used to securely access and manage devices or systems over a network. It encrypts the communication between the client and the server, ensuring secure data transmission.
Basic SSH Command
ssh [user]@[hostname]
How to SSH into a Server
Prerequisites
- You need the username (
$server_user$) and domain name or IP address ($server_domain_name$) of the server. - Ensure that SSH is enabled on the server.
Steps to Connect
- Open a terminal or command prompt.
- Run the following command:
ssh $server_user$@$server_domain_name$ - Enter the password when prompted.
Using VSCode Remote SSH Extension
Prerequisites
- Host Machine: Windows.
- Remote Machine: Linux.
- Install VSCode and the Remote - SSH extension.
Steps to Connect
-
Create an SSH Key on your Windows machine:
ssh-keygen -t rsa -b 4096- This will generate a public/private key pair in the default path:
C:\Users\username\.ssh\id_rsa.pub.
- This will generate a public/private key pair in the default path:
-
Copy the Public Key:
- Navigate to the
.sshdirectory on your Windows machine:cd C:\Users\username\.ssh - Open the
id_rsa.pubfile in a text editor and copy its contents.
- Navigate to the
-
Add the Key to the Remote Machine:
- SSH into the remote Linux machine:
ssh $server_user$@$server_domain_name$ - Append the public key to the
authorized_keysfile:echo "your-public-key-contents" >> ~/.ssh/authorized_keys
- SSH into the remote Linux machine:
-
Connect Using VSCode:
- Open VSCode.
- Press
Ctrl+Shift+Pand select Remote-SSH: Connect to Host. - Enter the details for
$server_user$@$server_domain_name$. - Follow the prompts to connect securely.
Troubleshooting Tips
Common Issues
- Ensure SSH is installed and enabled on both machines.
- Double-check the hostname or IP address and username.
- Confirm the public key was added correctly to
authorized_keysusing cat or nano (cat ~/.ssh/authorized_keys) or (nano ~/.ssh/authorized_keys).