Ssh From Linux To Linux

Ssh From Linux To Linux

Reading time1 min
#Linux#SSH#Networking#OpenSSH#SCP#Sysadmin

How to SSH from Linux to Linux: A Practical Guide

Rationale:

Secure Shell (SSH) is an essential tool for Linux users, allowing secure remote access and management of a machine over a network. Whether you're a sysadmin, developer, or just a Linux enthusiast, knowing how to SSH from one Linux machine to another can save you time and enhance your productivity.

Hook:

Imagine remotely managing your Linux server, transferring files seamlessly, or running commands on a distant machine as if you were sitting right in front of it—all with the power of SSH. Let’s dive into how to make that happen.


What Is SSH?

SSH, or Secure Shell, is a protocol that allows you to establish a secure channel between two networked devices. It encrypts data, protecting your commands and transferred files against eavesdropping and tampering.


Prerequisites

  • Two Linux machines (or VMs) on the same network or accessible over the internet.
  • User access on both machines.
  • SSH server (sshd) installed and running on the remote machine.
  • SSH client installed on the local machine.

Most Linux distributions come with the SSH client installed by default (ssh command). The server (sshd) may need installation and configuration.


Step 1: Ensure SSH Server Is Installed on the Remote Machine

On the machine you want to connect to (remote machine), check if SSH server is installed:

sudo systemctl status sshd
  • If it says Unit sshd.service could not be found, install it:

For Ubuntu/Debian:

sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh

For CentOS/RHEL/Fedora:

sudo yum install openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd

Verify it’s running:

sudo systemctl status sshd

Step 2: Find the Remote Machine’s IP Address

On the remote machine:

ip a

Look for the IP address on the relevant network interface (e.g., eth0, wlan0). You should see something like:

inet 192.168.1.15/24

Here, IP is 192.168.1.15.


Step 3: Connect from the Local Machine Using SSH

From your local machine (the machine you’re sitting at), run:

ssh username@192.168.1.15

Replace username with your user on the remote machine, and 192.168.1.15 with its IP address.

  • On connection, if it’s your first time, you’ll see a message:
The authenticity of host '192.168.1.15 (192.168.1.15)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? 

Type yes and press Enter.

  • Then enter the password of your user on the remote machine.

If successful, your prompt will change to something like:

username@remote-machine:~$

You’re now logged into the remote Linux machine via SSH!


Step 4: Basic SSH Commands to Know

While connected, you can run any command as if you were local. Here are handy commands:

  • List files:
ls -la
  • Check disk space:
df -h
  • Transfer files: (covered next)

Step 5: Transfer Files Using SCP

SCP (Secure Copy) uses SSH to transfer files securely.

  • To copy a file from local to remote:
scp /path/to/local/file.txt username@192.168.1.15:/home/username/
  • To copy a file from remote to local:
scp username@192.168.1.15:/home/username/file.txt /path/to/local/destination/

Step 6: Set Up SSH Key-Based Authentication (Optional but Recommended)

Typing your password every time can be tedious. Instead, use SSH keys:

  1. Generate a key pair on your local machine:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

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

  1. Copy the public key to remote machine:
ssh-copy-id username@192.168.1.15

Enter your password when prompted.

  1. Now SSH connections will use the key instead of a password:
ssh username@192.168.1.15

Troubleshooting Tips

  • Ensure SSH port 22 is open and not blocked by firewall on the remote machine.
sudo ufw allow ssh       # for Ubuntu with ufw
sudo firewall-cmd --permanent --add-service=ssh    # for CentOS/RHEL
sudo firewall-cmd --reload
  • Check SSH server logs if connection fails:
sudo journalctl -u sshd
  • If you cannot connect by hostname, use IP address or configure DNS.

Conclusion

SSH is your go-to tool for securely managing remote Linux machines. With the few simple steps above, you can easily connect from Linux to Linux, transfer files, and even passwordlessly authenticate. Start practicing these commands today and make remote Linux management a breeze.


If you found this guide useful, feel free to leave a comment or share it with your Linux-enthusiast friends!


Happy SSHing!