I have two ubuntu computer shared the same wifi and desire to reach another from one's terminal.

First create an user on the second computer named "Second" and hostname "Algorithms"

Then tried to reach it from the other with SSH, but get error report as

$ ssh second@Algorithms  
ssh: Could not resolve hostname algorithms: nodename nor servname provided, or not known

The solution I tried is based on networking - Reach other computer from the local - Ask Ubuntu

What's the problem with my experiment?

  • it prompt: ssh: connect to host algorithms.local port 22: Connection refuse @user68186 Jan 8, 2019 at 13:43
  • thank you. Your comment clicks with me. Could you please transmit the comment to answer. @user68186 Jan 8, 2019 at 15:00
  • I am writing an answer.
    – user68186
    Jan 8, 2019 at 15:06

3 Answers 3


ssh within a home Local Area Network (LAN)

I assume there are two users each with their own computers running Ubuntu.

  • user1 uses comp1 and
  • user2 uses comp2.

The goal is for user1 to remotely access comp2 using user2's account in comp2.

Note: If user1 has an account in comp2 and user1 wishes to access her account in comp2 from comp1 then she she does not have to specify the username in the ssh command. ssh comp2.local will work.

Setup ssh server in comp2

For this you will need to physically go to comp2 and login to it using an account with administration privileges. I assume that is, user2 account.

Install the ssh server

Desktop Ubuntu does not come with any servers. To ssh into comp2 you will first need to install the openssh-server. Open a terminal in comp2 by pressing Ctrl+Alt+T and enter the following lines one at a time:

sudo apt update
sudo apt install openssh-server

You will be asked for user2's password. When you type the password the cursor will not move and it will seem like nothing is happening. This is normal. Hit Enter after typing the password. Then follow the instructions.

Once openssh-server is installed you will see a new options in Settings under sharing called "RemoteLogin" and it will be "On":

enter image description here

The standard Ubuntu desktop does not come with any firewalls installed. If you have a firewall installed then make sure it allows connections to port 22 from within the LAN. The instructions will depend on the specific firewall software.

Test ssh locally

Still at the terminal of comp2 test that ssh is working. Enter the command:


The refers to the IP address of the computer you are using. In other words, you are trying to ssh from comp2 to comp2. If all goes well you will be asked if you are sure you want to connect and then for your password. Once you answer yes for being sure and enter the password for user2 you will see the terminal prompt change from user2@comp2$ to [email protected]$. This shows that you have successfully sshed from comp2 to itself.

Note: Since the same user (user2) is ssh-ing in this case, you don't need to specify ssh [email protected] in the ssh command.

ssh from comp1

To ssh from comp1 to comp2 you can either use the computer name (hostname) or its IP address. To find the IP address of comp2 use the ifconfig command in the terminal of comp2. You will see an address like 192.168.x.y, where x can be 0 or 1 and y can be any number between 2 and 255.

From a terminal in comp1 enter either:

ssh [email protected]


ssh [email protected]

Note: If you use the name of the computer then you must add .local at the end. If you use the local IP address, it may change from time to time if a fixed address is not assigned.

Security concerns

  1. Router setup
  2. Enable public key based authentication and disable password based authentication.
  3. Install and configure a firewall

1. Router setup

Make sure port 22 is not forwarded to any computers in the home router. This will prevent anyone from outside the home LAN use ssh to connect to the home computers.

The instructions are router specific and beyond the scope of this answer as it has nothing to do with Ubuntu.

If you do want set up port forwarding, see How to access home ssh server from outside via the Internet?

2. Enable public key based authentication and disable password based authentication

This is a more secure way to use ssh. It uses a private-public key pair. The private key remains in the trusted computer from which the ssh connection is made. In this case comp1. The public key goes to comp2. Once the keys are in place, you will disable password based authentication in the ssh server in comp2. If you disable password based authentication without making sure the key based authentication is working, then ssh will not work, as there will be no way to authenticate the remote user.

First generate the private-public key pair in the user1@comp1. This will need to be done at each user and each local computer from where you ssh to another computer. In a terminal enter:

ssh-keygen -t ed25519

This generates the newer and more secure key than RSA. If you want RSA type keys, then enter:

ssh-keygen -t rsa -b 4096

The process will prompt you for a passphrase. You can hit Enter if you don't want one. If you do enter a passphrase, you will be asked for it every time you ssh from comp1 to comp2. If you use a passphrase it should not be same as the password used for normal login.

Next you will need to copy the public key from comp1 to comp2. In the terminal in comp1 enter:

ssh-copy-id [email protected]

You will be asked to enter the login password of user2 in comp2. If you have other computers in the home LAN you want to ssh to from the user1@comp1 then you need not create a new key-pair. Copy the public key of user1@comp1 to the other user accounts in the other remote computers using the above command.

Once the public key is successfully copied to the user2 account of comp2 try to ssh again:

ssh [email protected]

Now you should be able to get into comp2 without user2's password. At this point one can either use the password or the public key you generated to log in. You can test this by creating a new user (or with an existing second user) in comp1, such as user1a. At this stage user1@comp1 will be able to ssh to user2@comp2 without password using the public key. On the other hand user1a@comp1 will need to use the password of user2 to ssh to user2@comp2.

The next step is to disable the password based authentication. You may want to do this locally in a terminal of comp2. Use the following command to create a new files at /etc/ssh/sshd_config.d/

sudo nano /etc/ssh/sshd_config.d/10-nopasswords

Then add the following lines:

PasswordAuthentication no
KbdInteractiveAuthentication no

ChallengeResponseAuthentication no

In newer versions of ssh servers: (sshd) the configuration option Challenge Response Authentication has been replaced with Kbd Interactive Authentication. Thanks to RL-S for pointing this out.

Use Ctrl+O to save the changes and Ctrl+X to exit the editor.

Finally, restart the ssh server with the new settings by the following command:

sudo systemctl restart ssh

Now user1@comp1 will still be able to ssh to user2@comp2 without password using the public key. On the other hand user1a@comp1 will get permission denied to ssh to user2@comp2.

3. Install and configure a firewall

There are many firewall software, and some of them are hard to configure. I suggest you install the "uncomplicated firewall" called ufw by the command:

sudo apt install ufw

To open the port 22 but only from within the home LAN use the command:

sudo ufw allow from 192.168.x.0/24 to any port 22 

Note: replace x with either 0 or 1 based on your router setup.

This firewall setting in comp2 stops anyone from outside the home LAN use ssh to connect to comp2. However, it allows anyone (using any computer) within the home LAN try to ssh into comp2. If comp2 is removed from home and taken somewhere else and connected to another "similar" network, say by WiFi, all the computers in that network will be allowed to access port 22 of comp2 by this firewall setting. For this reason I recommend password based authentication to be disabled and private-public key based authentication be used in all computers running the ssh server.

Hope this helps

  • 1
    +1 but I have three laptops. Suggest changing "desktop computers" to "machines" for broader audience. Jan 9, 2019 at 0:10
  • @WinEunuuchs2Unix Thanks for pointing this out. I have edited the text and removed "desktop". I prefer "computers" to "machine". I have also mentioned the OS (Ubuntu) to make it clear that it is not Windows to Ubuntu or Ubuntu to Windows kind of answer. On second thought, The answer works for Windows with WSL or native ssh client as well.
    – user68186
    Jan 9, 2019 at 15:52
  • 1
    appreciate it very much your elaborate instruction. What do you mean "Make sure port 22 is not forwarded to any computers in the home router." the forward here is the forward in "forward an email" Jan 10, 2019 at 2:44
  • 1
    In step "2. Enable public key based authentication and disable password based authentication", there has been a change: ChallengeResponseAuthentication has been replaced by KbdInteractiveAuthentication. See also here: askubuntu.com/questions/1403846/…
    – RL-S
    Jul 7, 2023 at 10:49
  • 1
    @RL-S Thanks for bringing this to my notice. I have edited the answer.
    – user68186
    Jul 7, 2023 at 16:48

Maybe try to ssh via IP not hostname?

You can check ip using ifconfig


Add a string to your /etc/hosts file like this:


For example: algorithms

Save /etc/hosts and try connecting again.

Anyway, as a quick solution, you can always connect directly via IP address:

ssh [email protected]
  • For this to work, you should first make sure the local IP address is fixed. Many routers or whatever network apparatus that connects your local computers into a LAN, assign varying 192.168.xxx.xxx addresses, e.g. in boot order.
    – db-inf
    Sep 28, 2020 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .