Access Linux Remotely with SSH and PuTTY: A Quick Guide

By Anup Moitra

Updated on:

Access Linux Remotely with SSH and PuTTY

Accessing a Linux machine remotely is essential for managing servers, troubleshooting, and performing system administration tasks efficiently. Secure Shell (SSH) is a powerful tool that allows users to connect to a remote Linux machine, while PuTTY is a widely-used SSH client for Windows systems. In this comprehensive guide, we will walk you through the process of setting up remote access to your Linux machine using both SSH and PuTTY.

Why Use SSH for Remote Access?

SSH is a secure and encrypted protocol that ensures data privacy and integrity when connecting to a remote machine. Unlike other remote connection protocols, SSH encrypts the session data, preventing eavesdropping and unauthorized access. Using SSH to access your Linux machine remotely offers several benefits:

  • Security: Encryption prevents data interception and hacking.
  • Efficiency: SSH provides a fast and reliable connection.
  • Remote Management: You can manage your Linux system from anywhere with an internet connection.

By using SSH, administrators can maintain full control over their Linux systems without needing physical access, making it ideal for cloud servers, remote troubleshooting, and system maintenance.

Prerequisites for SSH Remote Access

Before setting up SSH, ensure the following prerequisites are met:

  1. Linux Machine: You should have a Linux-based server or desktop.
  2. SSH Server Installed: The openssh-server package must be installed and running on the remote Linux machine.
  3. SSH Client: An SSH client, such as PuTTY, should be installed on the local machine (Windows) for remote connections.

Step 1: Install SSH Server on Your Linux Machine

Most modern Linux distributions come with the SSH server pre-installed, but you may need to manually install it in some cases. To install and configure the SSH server on your Linux machine, follow these steps:

  1. Open Terminal on the Linux machine.
  2. Install the OpenSSH server package with the following command:bashCopy codesudo apt update sudo apt install openssh-server
  3. Check the status of the SSH server to ensure it is running:bashCopy codesudo systemctl status ssh
  4. If the SSH server is not running, start it using:bashCopy codesudo systemctl start ssh

Once the SSH server is installed and running, your Linux machine will be ready to accept remote SSH connections.

Step 2: Configuring the Firewall to Allow SSH Connections

To allow remote access, you need to configure your firewall to permit SSH traffic. Here’s how to do it:

  1. Check Firewall Status: If your machine uses ufw (Uncomplicated Firewall), you can check its status with:bashCopy codesudo ufw status
  2. Allow SSH Traffic: Run the following command to allow incoming SSH connections through the firewall:bashCopy codesudo ufw allow ssh
  3. Enable Firewall: If the firewall is not enabled, activate it with:bashCopy codesudo ufw enable

By ensuring the firewall allows SSH traffic, you can establish secure connections to the Linux machine.

Step 3: Finding Your Linux Machine’s IP Address

To connect to the Linux machine remotely, you need its public or private IP address. Here’s how to find it:

  1. For Local Network (Private IP): Run the following command to find your private IP address:bashCopy codeip addr show Look for the inet field under your network interface (usually eth0 or wlan0).
  2. For Remote Access (Public IP): If you’re accessing the machine over the internet, you need the public IP address. You can find it by visiting websites like WhatIsMyIP or by using the curl command:bashCopy codecurl ifconfig.me

Step 4: Using SSH to Connect to Your Linux Machine

Now that your Linux machine is ready and you have its IP address, you can use SSH to connect to it. Follow these steps:

For Linux or macOS Users:

  1. Open a terminal on your local machine.
  2. Use the following SSH command to connect:bashCopy codessh username@ip_address Replace username with your Linux user account and ip_address with the machine’s IP address.
  3. If it’s your first time connecting to the machine, you will be prompted to confirm the authenticity of the host. Type yes to proceed.
  4. Enter your password when prompted, and you’ll be logged into your Linux machine remotely.

For Windows Users: Using PuTTY to Connect

  1. Download and Install PuTTY: Visit the PuTTY download page and install the client on your Windows machine.
  2. Launch PuTTY: Open the PuTTY application.
  3. Enter Connection Details: In the PuTTY window, enter the IP address of your Linux machine in the “Host Name (or IP address)” field. Ensure the port is set to 22 (default for SSH).
  4. Login to the Linux Machine: Click “Open” to start the SSH session. When prompted, enter your username and password to authenticate.

Step 5: Using SSH Keys for Secure Authentication

To enhance security, SSH keys can be used instead of passwords. SSH keys consist of a public and private key pair. Here’s how to set them up:

  1. Generate SSH Keys: On your local machine, run:bashCopy codessh-keygen -t rsa -b 4096 Follow the prompts to save the key and set a passphrase.
  2. Copy the Public Key to the Linux Machine: Use the ssh-copy-id command to transfer the public key to the remote machine:bashCopy codessh-copy-id username@ip_address
  3. Test Key-Based Authentication: Now, you can log in without a password by simply typing:bashCopy codessh username@ip_address

Using SSH keys is more secure than using a password and is recommended for remote access.

Troubleshooting Common SSH Issues

Issue 1: SSH Connection Refused

  • Solution: Ensure the SSH service is running on the remote machine using sudo systemctl status ssh. If the service is not running, start it with sudo systemctl start ssh.

Issue 2: Incorrect Password or Username

  • Solution: Double-check the username and password you’re using to connect. You can also try resetting the password if necessary.

Issue 3: Firewall Blocking SSH Access

  • Solution: Make sure your firewall allows SSH traffic. Use sudo ufw allow ssh to enable it.

Conclusion

SSH is an indispensable tool for remotely accessing and managing Linux machines. By following the steps outlined in this guide, you can securely and efficiently connect to your Linux server or desktop from anywhere. Whether you are using a Linux/macOS terminal or Windows with PuTTY, remote access via SSH provides a powerful way to manage your systems remotely.

Frequently Asked Questions (FAQ)

1. What is SSH and why should I use it?

SSH (Secure Shell) is a protocol that allows you to securely access and manage remote systems over a network. It is encrypted, meaning that it protects your data from potential eavesdropping.

2. How do I find my Linux machine’s IP address?

You can find your IP address by running the command ip addr or ifconfig in the terminal. Look for the inet field under the network interface to identify the IP.

3. How do I connect to my Linux machine using PuTTY on Windows?

Download and install PuTTY, then configure it with your Linux machine’s IP address, port 22, and SSH as the connection type. Click “Open” to initiate the connection and log in with your username and password.

4. Can I use Windows Command Prompt for SSH?

Yes, starting with Windows 10, you can use the built-in SSH client in Command Prompt. Just type ssh <username>@<IP_address> to connect.

5. How do I secure my SSH connection?

Use SSH keys instead of passwords, disable root login, and ensure your SSH server is up-to-date. You can also configure firewalls to allow SSH access only from trusted IP addresses.

6. What do I do if SSH is not installed on my Linux machine?

If SSH is not installed on your Linux machine, you can install it by running:

sudo apt-get install openssh-server

on Ubuntu or Debian-based distributions, or:

sudo yum install openssh-server

on CentOS or RHEL-based systems.

7. What if my SSH connection fails?

If you’re unable to connect via SSH, ensure that:

  • Your machine is connected to the network.
  • The SSH service is running on your Linux machine (sudo systemctl status ssh).
  • Port 22 is open in your firewall.
  • You’re using the correct IP address and login credentials.

Leave a Comment