🔑 How to Set Up SSH Access for Your VPS and Connect Using PuTTY

Introduction

When managing a VPS, secure remote access is essential. SSH (Secure Shell) allows you to connect to your server and execute commands as if you were physically there. For Windows users, PuTTY is a popular and free tool that makes SSH connections straightforward. In this guide, we’ll walk you through setting up SSH on your VPS, configuring PuTTY, and securing your connection with best practices.

Whether you’re hosting a web app, running Docker containers, or setting up a self-hosted solution, this guide will help you get started with SSH access the right way!


🛠 Step 1: Prepare Your VPS for SSH Access

  1. Log into your VPS: If you have console access or another way to log in temporarily, start there.
  2. Install the SSH Server:
    sudo apt update
    sudo apt install openssh-server
  3. Enable and Start SSH:
    sudo systemctl enable ssh
    sudo systemctl start ssh
  4. Verify SSH is Running:
    sudo systemctl status ssh
  5. Find Your VPS IP Address:
    hostname -I
    
    

    Step 2: Create a New User (Non-Root)

    For security, avoid using root for daily tasks.

    1. Create a new user:
      sudo adduser yourusername

      Follow the prompts to set a password.

    2. Grant sudo access:
      sudo usermod -aG sudo yourusername
    3. Switch to the new user:
      su - yourusername

🔐 Step 3: Configure the Firewall (if necessary)

If using UFW (Uncomplicated Firewall), allow SSH traffic:

sudo ufw allow ssh
sudo ufw enable

Or manually open port 22:

sudo ufw allow 22

🔑 Step 4: Generate and Add an SSH Key (Optional but Recommended)

  1. Generate SSH Key Pair (on your local machine): with Power Shell or CMD
    ssh-keygen -t rsa -b 4096
  2. Generate Key with PuTTYgen (Windows):
    • Open PuTTYgen (installed with PuTTY).
    • Select RSA and set the number of bits to 4096.
    • Click Generate and move your mouse to generate randomness.
    • Save the private key (.ppk) and copy the public key.
  3. Upload Your SSH Key to the VPS:

If you can’t use ssh-copy-id, manually upload the public key:

  1. Log into the VPS:
ssh username@your-server-ip
  1. Create the .ssh directory (if not already present):
mkdir -p ~/.ssh
chmod 700 ~/.ssh
  1. Open the authorized_keys file with nano:
nano ~/.ssh/authorized_keys
  1. Paste the Public Key: Paste your public key (from PuTTYgen or the .pub file) into the editor.

Example public key:

ssh-rsa AAAAB3Nz...your-key... user@local-machine
  1. Save and Exit:
  • Press CTRL + X to exit.
  • Press Y and Enter to save.
  1. Set Proper Permissions:
chmod 600 ~/.ssh/authorized_keys

💻 Step 5: Connect to VPS Using PuTTY (Windows)

  1. Download and Install PuTTY: PuTTY Download
  2. Configure the Connection:
    • Host Name: Your VPS IP
    • Port: 22 (or your custom port)
    • Connection Type: SSH
  3. (Optional) Add SSH Private Key:
    • In PuTTY, go to Connection → SSH → Auth and browse for your private key (.ppk).
  4. Connect and Login: Click Open, enter your username, and log in.

🔒 Secure SSH Before Proceeding

we choose port 222, let’s properly change it while ensuring you don’t get locked out.

  1. Enable UFW and allow essential ports:
    sudo ufw allow 222/tcp  # (Your SSH port)
    sudo ufw allow 80/tcp    # (HTTP for websites)
    sudo ufw allow 443/tcp   # (HTTPS for websites)
    sudo ufw enable
  2. Check firewall status:
    sudo ufw status

This ensures that only necessary services are accessible.

2️⃣ Change SSH Port to 222 Safely

Edit the SSH configuration file:

sudo nano /etc/ssh/sshd_config

  • Find

    #Port 22

  • Change to:

    Port 222

  • Ensure these lines exist:

    PermitRootLogin no

    PasswordAuthentication no

    PubkeyAuthentication yes

Save and restart SSH:

sudo systemctl restart ssh

 

3️⃣ Test SSH Before Closing Port 22

Keep your current SSH session open and open a new PuTTY session, but this time:

  • Use Port: 222
  • If it works, you can safely close Port 22:

    sudo ufw deny 22/tcp

    sudo ufw reload

     


if you face error with access with new port here are the Steps to Resolve the Port Change Issue keep current session runing and do the following

In this case, you can try reinstalling SSH:

sudo apt update

sudo apt install --reinstall openssh-server

 


📘 Conclusion

Setting up SSH access with PuTTY gives you a secure and reliable way to manage your VPS. By following the steps above, you’ve not only connected to your server but also hardened its security against threats. Whether you’re running a small personal project or managing business-critical infrastructure, this setup will serve as a solid foundation.

Have questions or run into issues? Let us know in the comments — we’re here to help! 🚀


About EngineerHow.com: Your go-to resource for IT and engineering tutorials, covering self-hosted solutions, networking, VPS setup, civil engineering, and more. Our step-by-step guides make complex topics simple so you can build, learn, and grow.


What do you think of this setup? Drop your questions or feedback in the comments below! 👇