Loading...
SSHLinuxUbuntuNetworkingDevOpsSecurity

SSH Basics: How to Setup SSH Between Two Ubuntu Computers

Mahnoor Rani
Mahnoor RaniSoftware Engineer
SSH Basics: How to Setup SSH Between Two Ubuntu Computers

SSH Basics: How to Setup SSH Between Two Ubuntu Computers

If you've ever needed to control one computer from another, or send files between two machines without plugging in a USB drive, then SSH is exactly what you need. It's one of the most important tools in a developer's toolkit, and once you understand it, you'll use it every single day.

In this article, we'll cover what SSH actually is, how data moves through it, and then walk through setting it up between two Ubuntu computers step by step.

What is SSH?

SSH stands for Secure Shell. It's a way to connect to another computer over a network and control it using the terminal. Think of it like making a phone call to another computer. Once the call connects, you can type commands on your machine, and they run on the other machine.

The key word here is secure. Before SSH existed, people used tools like Telnet to connect to remote machines. The problem? Telnet sent everything in plain text. That means if someone was watching the network traffic, they could see your passwords, your commands, everything. SSH fixes this by encrypting all the data that goes back and forth.

In simple terms:

  • SSH lets you control a remote computer from your terminal
  • Everything you send and receive is encrypted
  • It uses port 22 by default

How Does SSH Data Flow Work?

Before we jump into setup, let's understand what happens behind the scenes when you connect to another machine using SSH. This is the data flow.

Step 1: You Start the Connection

You type a command like this on your local machine (the client):

ssh username@192.168.1.50

This tells your computer: "Hey, I want to connect to the machine at IP address 192.168.1.50, using this username."

Step 2: The TCP Handshake

Your computer reaches out to the remote machine on port 22. A standard TCP connection is established first. This is just the two computers agreeing to talk to each other, like picking up the phone before you start speaking.

Step 3: Key Exchange (The Security Part)

This is where the magic happens. Before any real data is sent, the two machines perform a key exchange. Here's what goes on:

  1. The server sends its public host key to your computer. This is like the server showing its ID card.
  2. Your computer checks if it recognizes this key. If it's your first time connecting, you'll see a message like:
The authenticity of host '192.168.1.50' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no)?
  1. If you type yes, your computer saves this key so it won't ask again next time.
  2. Both machines then agree on a session encryption key using algorithms like Diffie-Hellman. This key is used to encrypt everything for the rest of the session.

Step 4: Authentication

Now the server needs to verify who you are. There are two common ways:

  • Password authentication: You type your password. It gets encrypted and sent to the server.
  • Key-based authentication: Your computer sends a digital signature using your private key. The server checks it against your public key. No password needed. This is the more secure method.

Step 5: The Encrypted Session

Once you're authenticated, you're in. A secure, encrypted tunnel is now open between the two machines. Every command you type travels through this tunnel, gets executed on the remote machine, and the output travels back to you, all encrypted.

Here's a simple diagram of the flow:

[Your Computer]  --->  TCP Connection (Port 22)  --->  [Remote Computer]
       |                                                       |
       |--- Key Exchange (agree on encryption) ----------------|
       |                                                       |
       |--- Authentication (password or SSH key) --------------|
       |                                                       |
       |========= Encrypted Tunnel Established ================|
       |                                                       |
       |--- You type commands -----> Commands execute there ---|
       |--- Output comes back <----- Results sent back --------|

Setting Up SSH Between Two Ubuntu Computers

Now let's get our hands dirty. We'll call the two machines:

  • Computer A - Your local machine (the one you'll type commands on)
  • Computer B - The remote machine (the one you want to connect to)

What You'll Need

  • Both computers running Ubuntu (any recent version works)
  • Both computers connected to the same network (or accessible over the internet)
  • The IP address of Computer B

Step 1: Install OpenSSH Server on Computer B

By default, Ubuntu comes with the SSH client installed, but not the server. You need to install the SSH server on the machine you want to connect to.

On Computer B, open a terminal and run:

sudo apt update
sudo apt install openssh-server

Once installed, the SSH service starts automatically. You can verify it's running:

sudo systemctl status ssh

You should see something like "active (running)" in green. If it's not running, start it:

sudo systemctl start ssh
sudo systemctl enable ssh

The enable command makes sure SSH starts automatically every time Computer B boots up.

Step 2: Find the IP Address of Computer B

Still on Computer B, run:

ip a

Look for the line that starts with inet under your network interface (usually eth0 for wired or wlan0 for Wi-Fi). It will look something like:

inet 192.168.1.50/24

That 192.168.1.50 is the IP address you'll use to connect. Write it down.

Step 3: Connect from Computer A

Now switch to Computer A. Open a terminal and type:

ssh username@192.168.1.50

Replace username with the actual username on Computer B, and 192.168.1.50 with Computer B's actual IP address.

The first time you connect, you'll see the fingerprint message we talked about earlier. Type yes to continue, then enter the password for that user on Computer B.

That's it. You're now controlling Computer B from Computer A's terminal.

Step 4: Setup SSH Key Authentication (No More Passwords)

Typing a password every time gets old fast. Let's set up key-based authentication instead.

On Computer A, generate an SSH key pair:

ssh-keygen -t ed25519 -C "your-email@example.com"

When it asks where to save the key, just press Enter to use the default location (~/.ssh/id_ed25519). You can also set a passphrase for extra security, or leave it empty.

This creates two files:

  • ~/.ssh/id_ed25519 - Your private key (never share this with anyone)
  • ~/.ssh/id_ed25519.pub - Your public key (this one goes to Computer B)

Now copy the public key to Computer B:

ssh-copy-id username@192.168.1.50

It will ask for your password one last time. After that, your public key is added to Computer B's ~/.ssh/authorized_keys file.

Now try connecting again:

ssh username@192.168.1.50

This time, no password prompt. You're in. The two machines now trust each other through cryptographic keys.

Step 5: Configure the Firewall (If Needed)

If Computer B has a firewall enabled (Ubuntu uses UFW), you need to allow SSH traffic:

sudo ufw allow ssh
sudo ufw enable
sudo ufw status

This opens port 22 so incoming SSH connections can get through.

Useful SSH Commands to Know

Once you have SSH working, here are some commands you'll use often:

Copy a file from your computer to the remote machine:

scp myfile.txt username@192.168.1.50:/home/username/

Copy a file from the remote machine to your computer:

scp username@192.168.1.50:/home/username/report.pdf ./

Copy an entire folder:

scp -r myfolder username@192.168.1.50:/home/username/

Disconnect from the remote machine:

exit

Quick Troubleshooting Tips

If things don't work on the first try, here are common fixes:

  • "Connection refused" - The SSH server isn't running on Computer B. Run sudo systemctl start ssh.
  • "Permission denied" - Wrong password or your key isn't set up correctly. Double-check with ssh-copy-id.
  • "No route to host" - The machines can't reach each other on the network. Make sure they're on the same Wi-Fi or LAN.
  • "Host key verification failed" - The server's key changed (maybe it was reinstalled). Remove the old key with ssh-keygen -R 192.168.1.50 and try again.

What We Learned

Let's recap what we covered:

  1. SSH is a secure way to remotely control another computer over the network
  2. It works by establishing an encrypted tunnel after a key exchange and authentication
  3. We installed the OpenSSH server on the remote machine
  4. We connected using password authentication first
  5. Then we upgraded to key-based authentication for convenience and better security
  6. We learned useful commands like scp for file transfers

SSH is one of those foundational skills that every developer, system admin, and DevOps engineer uses daily. Whether you're deploying code to a server, managing cloud instances, or just transferring files between your machines at home, SSH has got you covered.

Final Thoughts

SSH might seem intimidating at first, but once you set it up once, it becomes second nature. Start with password authentication to get comfortable, then move to SSH keys. The more you use it, the more you'll wonder how you ever worked without it.

Follow Kohminds for more beginner-friendly tech guides, tutorials, and developer insights.

About the Author

Mahnoor Rani

Mahnoor Rani

Software Engineer

Connect on LinkedIn