How To Ssh On Linux

How To Ssh On Linux

Reading time1 min
#Linux#SSH#Security#OpenSSH#RemoteAccess#Sysadmin

How to SSH on Linux: A Practical Guide for Beginners

Rationale:
SSH (Secure Shell) is an essential tool for managing remote Linux servers securely. Whether you’re a developer, sysadmin, or hobbyist, knowing how to use SSH efficiently can save you time and improve your workflow.

Hook:
Imagine controlling your Linux server from anywhere in the world with just a simple command—no need to physically access the machine. SSH makes it possible and it’s easier than you might think!


What is SSH?

SSH stands for Secure Shell. It’s a cryptographic network protocol that lets you securely connect to a remote computer—usually a Linux server—over an unsecured network like the internet. When you SSH into a server, you get terminal access as if you were sitting right in front of it.


Before You Start: What You Need

  • A remote server running an SSH server (most Linux distros come with OpenSSH server installed or easily installable).
  • Your local Linux machine (or macOS; Windows users can use WSL or tools like PuTTY).
  • The IP address or hostname of the remote server.
  • A username on the remote server.
  • Optional but recommended: SSH key pair for authentication instead of passwords.

Step 1: Check if SSH Client is Installed

On your local Linux machine, open a terminal and type:

ssh -V

You should see something like:

OpenSSH_8.4p1, LibreSSL 2.8.3

If it’s missing, install it:

sudo apt update && sudo apt install openssh-client

(on Debian/Ubuntu systems)


Step 2: Connecting to a Remote Server via SSH

The basic SSH command syntax is:

ssh username@remote_server_ip_or_hostname

For example:

ssh john@192.168.1.10

You’ll be prompted for your password. After typing it correctly, you gain shell access.


Example Session:

$ ssh john@192.168.1.10
john@192.168.1.10's password:
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-60-generic x86_64)

john@server:~$

Now you can run commands on the remote machine as if you were directly logged in.


Step 3: Using SSH Keys for Passwordless Login (Recommended)

Instead of entering a password every time, generate an SSH key pair on your local machine and copy the public key to the server.

Generate Key Pair

Run this command locally:

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

Press Enter to accept default file location (~/.ssh/id_rsa) and optionally add a passphrase.

Copy Public Key to Server

Use ssh-copy-id to transfer your public key:

ssh-copy-id john@192.168.1.10

Enter your password one last time.

Now try logging in again:

ssh john@192.168.1.10

You should get logged in without needing to input your password!


Step 4: Useful SSH Options

  • Specify custom port (if different from default port 22):
ssh -p 2222 john@192.168.1.10
  • Run a command directly without starting interactive shell:
ssh john@192.168.1.10 'ls -la /var/www'
  • Enable verbose output for troubleshooting:
ssh -v john@192.168.1.10

Step 5: Configuring Your SSH Client for Convenience

Edit ~/.ssh/config on your local machine to create shortcuts:

Example config:

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

Now just type:

ssh myserver

to connect!


Troubleshooting Tips

  • Make sure the remote server has an SSH server running:
sudo systemctl status sshd   # or ssh on some distros 
  • Check firewall rules blocking port 22.
  • Verify correct username and IP address.
  • Look at logs on the server /var/log/auth.log.

Conclusion

SSH is your gateway to securely managing Linux machines remotely with ease and confidence once you understand the basics outlined here.

With this knowledge, you can now connect, manage files remotely, tunnel traffic securely, or even automate tasks over SSH!

Got questions? Drop them in the comments—happy to help!


Happy shelling! 🐚✨