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 (192.168.0.12)' 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:  https://help.ubuntu.com

 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

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


     https://microk8s.io/docs/commands#microk8s.status

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 192.168.0.30



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@192.168.0.12


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

$ ssh nvidia@192.168.0.12
ssh: connect to host 192.168.0.12 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 192.168.0.0/24
Starting Nmap 7.80 ( https://nmap.org ) 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 (192.168.0.1)
Host is up (0.015s latency).
Nmap scan report for ***MobilePhone_01*** (192.168.0.20)
Host is up (0.016s latency).
Nmap scan report for nvidia-nano (192.168.0.23)
Host is up (0.10s latency).
Nmap scan report for ***AndroidPhone*** (192.168.0.15)
Host is up (0.100s latency).
Nmap scan report for ***iPhone*** (192.168.0.53)
Host is up (0.012s latency).
Nmap scan report for ***user-laptop1*** (192.168.0.61)
...
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
logout
Connection to nvidia-nano closed.

1 comment:

micheal pan said...

BE SMART AND BECOME RICH IN LESS THAN 3DAYS....It all depends on how fast 
you can be to get the new PROGRAMMED blank ATM card that is capable of
hacking into any ATM machine,anywhere in the world. I got to know about 
this BLANK ATM CARD when I was searching for job online about a month 
ago..It has really changed my life for good and now I can say I'm rich and 
I can never be poor again. The least money I get in a day with it is about 
$50,000.(fifty thousand USD) Every now and then I keeping pumping money 
into my account. Though is illegal,there is no risk of being caught 
,because it has been programmed in such a way that it is not traceable,it 
also has a technique that makes it impossible for the CCTVs to detect 
you..For details on how to get yours today, email the hackers on : (
atmmachinehackers1@gmail.com ). Tell your 
loved once too, and start to live large. That's the simple testimony of how 
my life changed for good...Love you all ...the email address again is ;
atmmachinehackers1@gmail.com