Skip to main content

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

  1. Open a terminal or command prompt.
  2. Run the following command:
    ssh $server_user$@$server_domain_name$
  3. 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

  1. 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.
  2. Copy the Public Key:

    • Navigate to the .ssh directory on your Windows machine:
      cd C:\Users\username\.ssh
    • Open the id_rsa.pub file in a text editor and copy its contents.
  3. 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_keys file:
      echo "your-public-key-contents" >> ~/.ssh/authorized_keys
  4. Connect Using VSCode:

    • Open VSCode.
    • Press Ctrl+Shift+P and 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_keys using cat or nano (cat ~/.ssh/authorized_keys) or (nano ~/.ssh/authorized_keys).