Connecting To Host In A Same Network(LAN) Via SSH

SSH(Secure Shell) is a cryptographic network protocol that allow you to operate network services securely over an unsecured network. There are multiple client in various OS to run ssh. For example, In Linux OpenSSH and in Windows PuTTY is there.
Now suppose you have a home router and there are multiple network connected to it and certainly you want to access a computer from another computer. Let’s take Comp1 wants to connect to Comp2. So, Now you have to create a SSH connection between the computers.

Setting up the SSH Server

So for connection you have to install and start a SSH server in the Comp2 . Let’s see the commands for installing SSH server.

$ sudo apt install openssh-server

Now you have to check SSH service is running or not if not you have to start it.

$ sudo systemctl status ssh

If the status is not showing active in your case the you have to execute the below command

$ sudo systemctl enable ssh

Get the IP of the Server

We connect to a server by $ ssh user@ip_address so you have figure out the ip address of the Comp2 . And for that you can type ifconfig . Your ip will be something like 192.168.x.y

Enabling SSH traffic on your firewall settings

If you are using UFW as a default firewall on your Ubuntu host, it is likely that you need to allow SSH connections on your host.

To enable SSH connections on your host, run the following command –

$ sudo ufw allow ssh

Then check for firewall has enabled or not –

$ sudo ufw status | grep 22

It should give something like this –

Note : SSH use port 22 by default.

Connecting via SSh

Now go to the Comp2 and type the ssh command followed by the user@ip_address. In my case bellow –

$ ssh aniruddha@192.168.1.5

Then it will prompt for the password and type the password for that user in the computer and here you go your Comp2 terminal will appear in the Comp1 terminal.

Advertisement

Authenticate github using ssh

SSH is a tool by which we can create a secure connection between the client and server. Basically it is an asymmetric type encryption that creates two key one is public and one is private. Public key can be distributed publicly and it is used for encrypt the data and the private key have to be kept secret for decrypting the data. Below commands will create the ssh keys:

$ ssh-keygen -t rsa -C "your_email@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ani/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ani/.ssh/id_rsa.
Your public key has been saved in /home/ani/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Up6KjbnEV4Hgfo75YM393QdQsK3Z0aTNBz0DoirrW+c ylo@klar
The key's randomart image is:
+---[RSA 2048]----+
|    .      ..oo..|
|   . . .  . .o.X.|
|    . . o.  ..+ B|
|   .   o.o  .+ ..|
|    ..o.S   o..  |
|   . %o=      .  |
|    @.B...     . |
|   o.=. o. . .  .|
|    .oo  E. . .. |
+----[SHA256]-----+

Now you have created a pair of keys and you have to add the public key in the github. Follow below instructions after doing the above the task –

  1. Go to your github page and open settings.
  2. Now click the SSH and GPG keys.
  3. Now click New SSH key.
  4. In the title field add a relevant title fr your key. Like if you are using Linux on your PC the give a title like “Linux PC”.
  5. Then paste your public key in the box.
  6. Then click Add SSH key.
  7. If it ask for your password then confirm your password.

Thank you 🙂