Skip to content

SSH into a Local Network Device

Connect from a Linux machine to another device on the same local network. In this case we will use a headless Ubuntu box whose IP is already known as the device to connect. Simply using an alias registry in ~/.ssh/config lets you connect with a short command instead of the full user and IP.

If the file does not exist, create it and set permissions. SSH ignores config and key files that are too open.

Terminal window
mkdir -p ~/.ssh
touch ~/.ssh/config
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config

Open ~/.ssh/config and append the block below. Replace 192.168.1.5 with the target device IP and your user with the Linux username on that device. No extra file is needed for password login or the default SSH key.

Terminal window
nano ~/.ssh/config
Terminal window
Host local-ubuntu
HostName 192.168.1.6
User your-user

Once saved, connect using the alias.

Terminal window
ssh local-ubuntu

The equivalent direct command without an alias:

Terminal window
ssh myuser@192.168.1.5

On the first connection, SSH asks whether to trust the host fingerprint. Type yes if the IP and device are correct. If the target is configured for password login, the password prompt will show up.

After connection, move files when needed with scp command. Copy all files in a driectory with * or copy a specific file by filename.

Terminal window
scp -r $USER@192.168.1.5:/home/$USER/myproject/* ~/projects/myproject/

Check file/folder sizes whenever needed in this process with du command.

Terminal window
du -sh /path/to/folder

Run SSH with verbose output to see where a failed connection breaks down.

Terminal window
ssh -v local-ubuntu

If ssh reports ‘No route to host’, confirm basic reachability from the host machine and verify the target IP from the target machine itself.

Terminal window
# From the host
ping 192.168.1.5
# From the target device
ip addr

If the target device is reachable on the network but SSH fails to connect, confirm the SSH server is installed and running on the target.

Terminal window
# On the target Ubuntu device
sudo systemctl status ssh
# If not installed
sudo apt update
sudo apt install openssh-server
sudo systemctl enable --now ssh