How To Ssh Into A Linux Machine

How To Ssh Into A Linux Machine

Reading time1 min
#Linux#SSH#RemoteAccess#SecureShell#OpenSSH

How to SSH into a Linux Machine: A Practical Step-by-Step Guide

Rationale:
SSH (Secure Shell) is one of the most powerful tools in a Linux user’s toolbox. Whether you’re managing servers, accessing remote machines for work, or just tinkering around, knowing how to securely connect via SSH is essential. This guide walks you through the entire process with simple examples.

Hook:
Imagine needing to manage your home server from anywhere in the world with just a few keystrokes—no cables, no extra hardware. SSH makes that possible. Ready to master it?


What is SSH and Why Use It?

SSH stands for Secure Shell. It’s a protocol that allows you to securely connect to another computer over an unsecured network. It encrypts all data exchanged between your local machine and the remote server, preventing eavesdropping and attacks.

Typical use cases:

  • Remotely administering Linux servers
  • Transferring files securely
  • Running commands on a remote machine without physical access

Prerequisites

Before connecting via SSH, you need:

  1. A remote Linux machine: This could be a server or another computer on your network.
  2. SSH enabled on the remote machine: Most Linux distributions have OpenSSH server installed or available.
  3. Network access: Your local machine must be able to reach the remote host via IP address or hostname.
  4. Credentials: Username and password or an SSH key pair for authentication.

Step 1: Check if SSH Client is Installed Locally

Most Linux and macOS systems have ssh installed by default.

Open your terminal and type:

ssh -V

You should see output similar to:

OpenSSH_9.0p1, LibreSSL 2.8.3

If not installed (e.g., on Windows or minimal distros), here’s how to install it:

  • On Ubuntu/Debian:
sudo apt update
sudo apt install openssh-client
  • On Windows: Consider using PuTTY or enable Windows Subsystem for Linux (WSL).

Step 2: Confirm SSH Server is Running on Remote Machine

You need the OpenSSH server running on your remote Linux machine.

Check status with:

sudo systemctl status ssh

If it’s inactive/not installed:

  • Install OpenSSH server (Ubuntu/Debian):
sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh --now
  • Check firewall rules ensure port 22 (default SSH port) is open:
sudo ufw allow ssh

Step 3: Get Remote Machine’s Address and Username

You need two pieces of info:

  • IP address or hostname of remote machine
  • Username you want to log in as

To find IP address on the remote machine:

ip addr show

Look for an IP like 192.168.x.x in case of LAN connection.

To see current username:

whoami

Step 4: Connect Using SSH Command

The basic syntax is:

ssh username@remote_host

Example:

Let's say your username is alice and your server's IP is 192.168.1.10, run:

ssh alice@192.168.1.10

If it's your first time connecting, you'll get a message like this:

The authenticity of host '192.168.1.10 (192.168.1.10)' can't be established.
ECDSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)?

Type yes and press Enter to continue.

Then enter your password when prompted.


Step 5: Disable Password Authentication (Optional but Recommended)

For better security, switch from password authentication to key-based login.


Generate SSH Key Pair Locally

Run:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Press Enter to accept defaults and optionally protect the key with a passphrase.

This creates keys under ~/.ssh/id_rsa (private) and ~/.ssh/id_rsa.pub (public).


Copy Public Key to Remote Host

Use ssh-copy-id tool:

ssh-copy-id alice@192.168.1.10

Enter password once—it copies your public key into /home/alice/.ssh/authorized_keys.

Now try logging in again; this time no password is asked:

ssh alice@192.168.1.10

Troubleshooting Tips

  • Connection refused? Check if SSH server is running.
  • Timed out? Confirm network connectivity & firewall settings.
  • Permission denied? Re-check username/password or keys.
  • Port not standard? If SSH runs on another port like 2222, specify it via -p option:
ssh -p 2222 alice@192.168.1.10

Bonus: Customizing Your SSH Connection

You can create entries in your local ~/.ssh/config file for easier access:

Host myserver
    HostName 192.168.1.10
    User alice
    Port 22
    IdentityFile ~/.ssh/id_rsa  

Then simply connect by typing:

ssh myserver

Conclusion

SSH is an invaluable tool that unlocks powerful remote management capabilities — all through your terminal! With just a few straightforward commands, you can securely access any Linux machine wherever you are.

Master these steps today and take control of your remote servers effortlessly!


If you found this guide helpful or have any questions about SSH tips and tricks, leave a comment below! Happy connecting! 🚀