To connect to another computer on your local network using SSH, follow these steps:
✅ Prerequisites
- SSH Server must be installed and running on the target computer (the one you want to connect to).
- Both computers must be connected to the same local network.
- You need the IP address of the target computer.
- Optional but recommended: Set up SSH key-based authentication for security.
🔧 Step-by-Step Guide
1️⃣ Check SSH Server is Running on Target Computer
On the target computer (the one you want to connect to):
For Ubuntu/Debian:
sudo apt update
sudo apt install openssh-server
sudo systemctl status ssh # Make sure it's running
For CentOS/RHEL/Fedora:
sudo dnf install openssh-server
sudo systemctl start sshd
sudo systemctl enable sshd
sudo systemctl status sshd
For macOS:
SSH server is pre-installed and usually enabled. You can start it manually via:
sudo systemsetup -setremotelogin on
2️⃣ Find the IP Address of the Target Computer
On the target computer, run:
ip a
Look for an IP under a network interface, like 192.168.x.x or 10.x.x.x.
Alternatively:
hostname -I # Linux/macOS
3️⃣ Allow SSH Through Firewall (if applicable)
Make sure port 22 is open.
UFW (Ubuntu):
sudo ufw allow ssh
# or explicitly
sudo ufw allow 22/tcp
firewalld (Fedora/CentOS):
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
4️⃣ Connect via SSH from Your Computer
From your local computer (the one initiating the connection), run:
ssh username@target_ip
🔁 Replace:
username with the login name of the target computer.
target_ip with the IP address you found earlier.
✅ Example:
ssh alice@192.168.1.15
If it's your first time connecting, you'll be prompted to accept the host key.
🔐 Optional: Use SSH Key Authentication (Recommended)
Generate SSH keys on your local machine:
ssh-keygen
Copy your public key to the target machine:
ssh-copy-id username@target_ip
Now you can SSH without typing a password!
🛠 Troubleshooting Tips
- Connection refused? Make sure SSH server is running and port 22 is open.
- Wrong IP? Double-check the IP of the target machine.
- Still not working? Try pinging the target computer:
ping 192.168.1.15
Need help setting this up on Windows as well? Let me know!