Monday 23 December 2019

How to connect to Linux computer remotely via SSH

It is possible to access the terminal of the Linux machine in the same local network. All we need to know is:

  • account name we want to log in remotely
  • computer's IP address or hostname 

ssh connection

We can do this out of the box if we perform connection from Linux or Mac computer.

From Linux machine, via host name (nvidia-nano in this example; and nvidia as account name):

ssh nvidia@nvidia-nano
The authenticity of host 'nvidia-nano (' can't be established.
ECDSA key fingerprint is SHA256:AeGD/zmVkabo...ab3jLsqBUPjZfirAo.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'nvidia-nano' (ECDSA) to the list of known hosts.
nvidia@nvidia-nano's password: 
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.9.140-tegra aarch64)

 * Documentation:

 * Management:
 * Support:

 * Overheard at KubeCon: "microk8s.status just blew my mind".

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.

1 package can be updated.

0 updates are security updates.

Last login: Fri Dec 20 16:39:47 2019 from

We can run ifconfig on remote machine (directly) in order to determine its IP address. Once we know it, the ssh command would be e.g.:

$ ssh nvidia@

If we use the wrong IP address, we might get the following error:

$ ssh nvidia@
ssh: connect to host port 22: No route to host

It is possible to find out the IP address of the computer in local network via nmap tool which scans local network for connected devices. We need to know local network's address and mask:

$ nmap -sn
Starting Nmap 7.80 ( ) at 2019-12-07 23:36 GMT
Illegal character(s) in hostname -- replacing with '*'
Illegal character(s) in hostname -- replacing with '*'
Nmap scan report for xxxRouter (
Host is up (0.015s latency).
Nmap scan report for ***MobilePhone_01*** (
Host is up (0.016s latency).
Nmap scan report for nvidia-nano (
Host is up (0.10s latency).
Nmap scan report for ***AndroidPhone*** (
Host is up (0.100s latency).
Nmap scan report for ***iPhone*** (
Host is up (0.012s latency).
Nmap scan report for ***user-laptop1*** (
Nmap done: 256 IP addresses (7 hosts up) scanned in 3.59 seconds

To run applications that use dialogs (windows) we need to enable X forwarding by passing -X argument to ssh:

$ ssh -X user@host 
user@host: $ gedit

The example above will run gedit on a remote host but will open gedit window on the local host (from which we connect to remote). 

To execute command immediately upon connection, we can pass that command with -C ssh argument:

$ ssh -X user@host -C gedit

To close SSH connection we can use command exit:
nvidia@nvidia-nano:~$ exit
Connection to nvidia-nano closed.

No comments: