What's the best way to SSH to machines on the local network?

I have 2 computers, one that I use and one for the kids. I want to be able to ssh into their computer to control it (like to shut it down etc) but am curious the best way to do this. We both are in the same house and share the same internet connection.

What would be the best way to do this? From research, I read to install openssh-server on the remote computer but am stumped what to use for the hostname when trying to connect. Usually for VPS’s it’s the external IP but since we both share a wifi connection would it be the hardware IP? Should we be interfacing directly by LAN or by going through the internet?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1


avahi-browse -tl _workstation._tcp

To get a list of Ubuntu workstations in the local network, then you can connect to them by running:

ssh <username>@<computer-name>.local

Solution 2

You can use the IP address to ssh into the kid’s computer.
If you want to use the computer name, edit your /etc/hosts file to include the computer name.  dad  kids

Solution 3

Before doing ssh, check for ssh client and server. If you don’t have these services, install them with the following commands:

sudo apt-get install openssh-client

sudo apt-get install openssh-server

If you have already installed them, just do:

ssh [email protected]

and enter the connecting device login password.

If you get any error like : Permission denied, please try again., please check twice for Username and IP.

Solution 4

I use the file ~/.ssh/config which ssh parses automatically, here is an example:

Host *
ControlMaster auto
ControlPath /tmp/%[email protected]%h:%p

KeepAlive yes 
ServerAliveInterval 60
ServerAliveCountMax 10
ControlPersist 1h

Host server1
        User user1
        HostName server1-web.example.org

Host server2
        User user2
        HostName server2-db.example.org
        Compression yes
        IdentityFile /home/user/.ssh/different_key.pem

Note that you can use any (clientside) variable in this file and either set it globally or per server.

Solution 5

  1. You can ssh directly to a local IP provided that your LAN uses static IPs, for example
    ssh [email protected]

  2. You can edit hosts file in both computers, as mentioned by Ed Manet in his answer. That way you can then ssh using computer’s hostname, that is ssh [email protected]_hostname

  3. You can setup a local DNS server to resolve your LAN’s hosts. This way you will be able to ssh using the computer’s hostname as in option 2 but with additional benefit the avoidance of editing every hosts file, by pointing your DNS server in Ubuntu’s network settings.

DNSMasq is pretty good DNS server easy to setup.
Another option is BIND.

Solution 6

Use the local LAN IP address. The alternate approach requires some port to be open to the Internet, to allow you to login.

Also, you would need port mapping (on the router). Using your ‘public’ IP address (on the router) as a target will not connect to either of your two PCs.

The simplest way is to permanently assign each IP address (for your 2 computers) on the router. Then simply connect to that IP address.

If you want to get clever (later), set up a server and start using a local DNS service to assign meaningful names to each device. Not really worth the trouble for only 2 PCs.

Solution 7

If you are sharing the same internet connection you are most likely behind the same wifi router.
So you connect directly to your kids computer:

ssh <IP-address>


ssh <user-name>@<IP-address>

Obviously this works better if the kids computer has static IP address. Otherwise you always need to check what the IP is. Most routers have an option to assign static (always the same) IP to chosen devices. Some routers also have an option to assign host name to certain device – then for any device in the same network address “kids” would mean the same. If you assign host names with /etc/hosts file the host name is only known to that computer where that host file is. Also that assumes that kids computer has static IP address.

You can set static IP to kids computer also in that machine but I advice setup where network settings are done in the router. One point of control – easier to manage.
If something is unclear, leave a comment and I will expand my answer.

Solution 8

You can use the IP address in place of a hostname or assign a custom host name in your /etc/hosts file.

To get the IP on the kid’s computer: on the network menu see “Connection Information” or run ifconfig on the commandline (these have to be done on the kid’s computer).

Your wifi router assigns these IP addresses and you should be able to configure it to keep specific IP addresses for the computers they are currently assigned to. (Otherwise the IP’s may change from time to time).

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply