How to Connect to Your VPS Using SSH? Print

  • 0

Virtual Private Servers (VPS) are a powerful solution for hosting websites, applications, or development environments, offering full control over your server setup. Providers like VPS.DO make it easy to spin up a VPS with customizable resources. A key skill for managing your VPS is connecting to it securely via SSH (Secure Shell), which allows you to execute commands remotely. This article provides a practical, step-by-step guide to connecting to your Linux-based VPS using SSH, tailored for beginners and intermediate users, with tips for troubleshooting common issues.

What is SSH and Why Use It?

SSH is a cryptographic network protocol that enables secure communication between your local machine and a remote server, such as your VPS. It’s the standard for managing Linux servers due to its security and versatility. You’ll need SSH access details from your VPS provider, typically including an IP address, username (often root or a custom user), and a password or SSH key.

Prerequisites

Before starting, ensure you have:

  • VPS Details: IP address, username, and password or SSH key (check your VPS.DO dashboard or welcome email).

  • SSH Client: Most operating systems have built-in clients:

    • Linux/macOS: Use the ssh command in the terminal.

    • Windows: Use PowerShell, Windows Terminal, or third-party tools like PuTTY.

  • Network Access: Your local machine must have internet access, and the VPS’s SSH port (default: 22) must be open.

Step-by-Step Guide to Connect via SSH

1. Using SSH on Linux or macOS

Most Linux distributions and macOS have a built-in SSH client.

  1. Open Terminal: Launch your terminal application.

  2. Run SSH Command: Use the following format:

    ssh username@your.vps.ip.address

    Example: ssh root@192.168.1.1. If your VPS uses a non-standard port (e.g., 2222), specify it with -p:

    ssh -p 2222 username@your.vps.ip.address
  3. Authenticate:

    • Password: If prompted, enter the password provided by your VPS provider. It won’t display as you type for security.

    • SSH Key: If you’ve set up an SSH key (recommended), ensure it’s in ~/.ssh/ (e.g., id_rsa). The client will use it automatically if configured.

  4. Accept Host Key: The first time you connect, you may see a prompt about the server’s host key. Type yes to accept it.

  5. Connected: You should now see the VPS’s command-line interface.

2. Using SSH on Windows

Windows users can use PowerShell or a third-party client like PuTTY.

Option A: PowerShell

  1. Open PowerShell (search for “PowerShell” in the Start menu).

  2. Run the SSH command as above:

    ssh username@your.vps.ip.address
  3. Follow the same authentication steps as for Linux/macOS.

Option B: PuTTY

  1. Download PuTTY: Get it from the official website.

  2. Configure PuTTY:

    • Open PuTTY.

    • Enter your VPS’s IP address in the “Host Name (or IP address)” field.

    • Set the port (default: 22) under “Port.”

    • Select “SSH” as the connection type.

  3. Connect: Click “Open.” Log in with your username and password or configure an SSH key in the “Connection > SSH > Auth” section.

  4. Accept Host Key: Click “Yes” if prompted about the server’s key.

3. Setting Up SSH Keys (Optional but Recommended)

SSH keys are more secure than passwords and prevent brute-force attacks.

  1. Generate a Key Pair: On your local machine:

    ssh-keygen -t rsa -b 4096

    Press Enter to accept defaults or specify a custom file name. Optionally, set a passphrase.

  2. Copy the Public Key to the VPS:

    • Use ssh-copy-id (Linux/macOS):

      ssh-copy-id username@your.vps.ip.address
    • Or manually: Copy the content of ~/.ssh/id_rsa.pub and append it to ~/.ssh/authorized_keys on the VPS (create the file if it doesn’t exist).

  3. Test Key-Based Login: Run the SSH command again. You should connect without a password if configured correctly.

  4. Disable Password Login: For security, edit /etc/ssh/sshd_config on the VPS, set PasswordAuthentication no, and restart SSH:

    sudo systemctl restart sshd

Troubleshooting Common Issues

  • Connection Refused: Check if the VPS’s SSH port (default: 22) is open. Verify with your provider (e.g., VPS.DO’s support) if the firewall or network rules block it. Try:

    telnet your.vps.ip.address 22
  • Permission Denied: Double-check your username, password, or SSH key. Ensure the key is in ~/.ssh/authorized_keys with correct permissions (chmod 600 ~/.ssh/authorized_keys).

  • Timeout Errors: Confirm the IP address and ensure your local network allows outbound SSH connections.

  • PuTTY Key Format: If using PuTTY with SSH keys, convert your key to PuTTY’s format using PuTTYgen.

Best Practices

  • Use SSH Keys: They’re more secure than passwords.

  • Change Default Port: Modify the SSH port in /etc/ssh/sshd_config to reduce automated attacks.

  • Enable a Firewall: Use ufw or iptables to allow only necessary ports (e.g., sudo ufw allow 22).

  • Keep Software Updated: Run sudo apt update && sudo apt upgrade (Debian/Ubuntu) or equivalent to patch vulnerabilities.

Conclusion

Connecting to your VPS via SSH is a fundamental skill for server management. By following these steps, you can securely access your VPS and start configuring it for your needs. Providers like VPS.DO often include SSH setup instructions in their documentation, so check their support resources for specific guidance. With SSH access established, you’re ready to manage files, install software, or deploy applications on your VPS.


Was this answer helpful?

« Back