SSH on Linux VPS (Virtual Private Servers) Servers, It provides a secure way to give remote access and control. In this post, we will show you how to log into a Linux VPS with SSH using either the method of using a password or a public key.
Additionally, we will discuss popular SSH clients such as PuTTY, Termius, and Bitvise and examine cloud provider-specific methods for SSH key generation, including those from AWS, Google Cloud, and Azure. Whether you are new to Linux VPS management or looking to refine your SSH skills, this guide aims to equip you with the knowledge you need.
What is SSH?
SSH is a secure protocol to connect with another machine, which is usually a VPS(Linux Machine). Unlike standard remote access protocols, SSH encrypts the connection, so unauthorized users can’t intercept your data and commands. For server management, SSH commands are invaluable to system administrators as well as to those who develop and require secure communications.
Key Features of SSH
- Encryption: All data exchanged over SSH is encrypted, providing confidentiality and integrity.
- Authentication: SSH supports multiple authentication methods, including passwords and public key cryptography.
- Port Forwarding: SSH allows tunneling of other protocols, enabling secure access to different network services.
- File Transfer: With tools like SCP and SFTP, SSH facilitates secure file transfers between machines.
Requirements for SSH Access
Before you begin, ensure you have the following:
- A Linux VPS: This can be obtained from various providers like AWS, DigitalOcean, Google Cloud, and others.
- Server IP Address or Hostname: The public IP or hostname of your VPS.
- Username and Password or SSH Key: The credentials needed for login.
- An SSH Client: You’ll need depends on your operating system. Popular options include PuTTY, Termius, Bitvise, or Xshell.
How to Access SSH on Linux VPS
Method 1: Password-Based SSH Login
Password-based login is the simplest way to access your VPS via SSH. Follow these steps:
Step 1: Open Your Terminal or SSH Client
- For Linux or macOS: Use the Terminal application.
- For Windows: You can use an SSH client like PuTTY.
Step 2: Enter the SSH Command
In your terminal or SSH client, type the following command:
ssh username@server-ip
Replace username with your server username (often root) and server-ip with your VPS’s public IP address.
Example:
ssh [email protected]
Step 3: Enter Your Password
Type your password when asked. When you are successful, you will gain access to the VPS command line. Once you have logged in, you are able to start getting commands down and control your server.
Method 2: SSH Key-Based Login
A better way to log in is the SSH key. Here’s how to set it up:
Step 1: Generate an SSH Key Pair
Use the following command on Linux or macOS to generate an SSH key pair:
bash
ssh-keygen -t rsa
Use this command to generate a public and private key pair, typically stored in the ~/.ssh directory. Windows users can use PuTTYgen to generate their keys.
When prompted, you can accept the default file location by pressing Enter. You may also choose to add a passphrase for an extra layer of security.
Step 2: Copy the SSH Public Key to the VPS
To transfer your public key to the VPS, use the following command:
bash
ssh-copy-id username@server-ip
This command appends your public key to the authorized_keys file on the server, allowing for passwordless logins.
Example:
ssh-copy-id [email protected]
Step 3: Log in Using Your SSH Key
Now that you have set up key-based authentication, you can log into your VPS using your private key:
ssh -i /path/to/private_key username@server-ip
Example:
ssh -i ~/.ssh/id_rsa [email protected]
Once you have set up SSH keys, you will not need to enter a password, enhancing both convenience and security.
SSH Tools for Windows
To connect your Linux VPS while using Windows, you will need an SSH client. Below are some popular options:
PuTTY
Since many people use Windows, PuTTY is a free and very popular terminal emulator supported by different network protocols such as SSH (Secure Shell), so it is a very good tool to connect remotely to servers. Here’s a step-by-step guide on how to connect to a server using PuTTY:
- Download and Install PuTTY: First, download PuTTY from its official website. Select the right version for your operating system to download the installer and install the program.
- Launch PuTTY: Once installed, open PuTTY by clicking the shortcut or searching for it in your Start menu.
- Enter Server IP Address: In the PuTTY configuration window, locate the Hostname (or IP address) field. Make sure to set an IP address or domain name for the server you want to connect to. Ensure the Port field is set to the correct SSH port, which by default is 22.
- Configure SSH Connection: In the Connection type section, select SSH (if not already selected). If necessary, By entering a name in the Saved Sessions field, You can save the session and click Save; this is useful for quick access to frequently used servers. Servers.
- Connect to Server: Once everything is set, click Open to initiate the connection. If this is your first time connecting to the server, PuTTY may display a security alert about the server’s host key. You can safely accept it by clicking Yes (assuming you trust the server).
- Authentication: A terminal window will open, and you’ll be prompted to enter your server’s username. After entering your username, you’ll be asked to provide the password associated with that user. If you have configured SSH key-based authentication, you won’t need to enter a password but instead will use the private key you set up previously.
- Establishing Secure Access: Once authenticated, you’ll gain access to the server’s command line interface, where you can execute commands and manage the server securely.
Termius
Termius is a powerful, modern, cross-platform SSH client designed for developers and system administrators. Termius is accessible on Windows, Linux, macOS, iOS, and Android to allow control of remote servers from any device. In addition to supporting SSH, Termius introduces additional features such as SFTP, key management, and team collaboration. Here’s a step-by-step guide to help you get started:
- Download Termius: Visit the official Termius website and download the compatible version with your operating system (Windows, macOS, or Linux). You can also install it on mobile devices through the App Store or Google Play.
- Install Termius: After downloading the installer, follow the installation instructions. The setup process is simple, and once the installation is complete, you can launch Bitvise from your desktop or the Start menu.
- Set Up Termius: After signing in, you’ll be greeted with the Termius dashboard. Here, you can customize settings such as themes, key management, and other advanced features to fit your workflow.
Bitvise
A free SSH client for Windows, Bitvise is a powerful, graphical user friendly one. What it offers besides being a primary SSH client is file transfer, tunneling (port forwarding), and remote administration, making it a very popular choice among users who require more than just a local SSH client. Here’s how you can get started with Bitvise:
1. Download Bitvise:
Go to the official Bitvise website and download one version of the Bitvise SSH Client. Also, be on the lookout for the correct version of what you need for your operating system.
2. Install Bitvise:
After downloading the installer, run it and follow the installation instructions. The setup process is straightforward, and once the installation is complete, you can launch Bitvise from your desktop or the Start menu.
With Bitvise, you have a comprehensive SSH client that goes beyond basic terminal functionality. It is excellent for users requiring advanced file transfer and tunneling capabilities in an easy-to-use GUI
Xshell
Troubleshooting Common SSH Issues
But while using SSH, you will face different issues. Here are some common problems and how to resolve them:
1. Connection Timeout
If you encounter a connection timeout while trying to access your VPS, it might mean that the SSH service is currently not running. To resolve this issue, Restart the SSH service by executing the following command:
sudo service ssh restart
Make sure that your VPS is online and that you have set the correct IP address.
2. Permission Denied (publickey)
If you see a “Permission Denied” error while using SSH keys, ensure that your private key file has the correct permissions. You can set the appropriate permissions with the following:
chmod 600 ~/.ssh/id_rsa
Additionally, confirm that the public key has been properly added to the ~/.ssh/authorized_keys file on your server.
3. Firewall Blocking SSH
Ensure that your VPS firewall allows SSH traffic By running the following command:
sudo ufw allow ssh
If you are using a different firewall, such as iptables, make sure to configure it to allow port 22 (the default SSH port).
4. Incorrect Cloud Provider Key Association
Cloud providers such as AWS or Google Cloud ensure that the SSH key pair, in this case, is assigned to your instance. For AWS, you can verify the key pair attached to your EC2 instance in the instance’s settings.
Advanced SSH Configurations: Simplifying Login with SSH Config
For users who frequently connect to multiple servers, using an SSH config file can streamline the login process. Here’s how to set it up:
Step 1: Open or Create the SSH Config File
Use the following command to open (or create) the SSH config file:
nano ~/.ssh/config
Step 2: Add Server Details
Input your server details in the following format:
Host my server
HostName 123.45.67.89
User root
IdentityFile ~/.ssh/id_rsa
Step 3: Save the File
After adding the configuration, save the file. Now, you can log in using a simplified command:
ssh myserver
This configuration eliminates the need to remember the IP address and other details for each server you manage.
Additional SSH Features
File Transfers with SCP and SFTP
SSH also provides secure methods for transferring files between your local machine and the server.
Using SCP
Secure Copy Protocol (SCP) allows you to transfer files securely over SSH. The basic syntax is:
bash
scp /local/path username@server-ip:/remote/path
Example:
bash
scp ~/localfile.txt [email protected]:/home/root/
Using SFTP
Secure File Transfer Protocol (SFTP) is an interactive file transfer program that runs over SSH. You can start an SFTP session with:
sftp username@server-ip
Once in the SFTP shell, you can manage files using commands like put, get, ls, and cd.
Port Forwarding
SSH can also be used for port forwarding, which lets you tunnel network traffic through the SSH connection. It is very helpful if you want to connect to services running on your VPS that are not accessible publicly.
To set up local port forwarding, use the following syntax:
ssh -L local_port:localhost:remote_port username@server-ip
For example, to forward your local port 8080 on a web server running at port 80 on your VPS:
bash
ssh -L 8080:localhost:80 [email protected]
You can then access the web server by navigating to http://localhost:8080.
Conclusion
SSH is an important remote access tool for securely managing Linux VPS servers, providing flexibility and strong security. Regardless of whether you’re going with traditional password-based authentication, using key-based logins for added security, or using pre-generated keys that cloud platforms such as AWS or Google Cloud ship with services, you’ll want to know how to configure SSH and troubleshoot the tool itself.
Tools that make connecting to the Linux VPS easy for Windows users include PuTTY, Termius, Bitvise, and Xshell. More advanced features of the server can include the transfer of files and port forwarding.
This tutorial enables you to manage your Linux VPS securely using SSH, troubleshoot common issues, and accomplish your server management tasks with ease. Learn how to use SSH to streamline your workflow and make your server management that much easier. With practice and familiarity, you’ll find SSH a valuable addition to your toolkit for efficient server administration.
About the writer
Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.