Install and Configure SSH key in Linux


What is OpenSSH?

SSH (Secure Shell) is a tool for secure system administration, file transfers, and other communication across the Internet or other untrusted network. It encrypts identities, passwords, and transmitted data so that they cannot be eavesdropped and stolen.

OpenSSH is an open-source implementation of the SSH protocol. It is based on the free version by Tatu Ylonen and further developed by the OpenBSD team and the user community.

Thinks to remember
  • Make sure OpenSSH is installed on the workstation and server
  • Connect to the server from the workstation, answer "yes" to initial connection prompt
  • Create an SSH key pair (with a passphrase) for a normal user account
  • Copy that key to the server

Install OpenSSH

sudo apt install openssh-server 

Find the remote server ip

eg: 192.168.43..60

Do ssh in it

ssh 192.168.43.60

provide "yes" when it asks and default user password you will be connected to the server

Methode II

ssh username@192.168.43.60

provide "yes" when it asks and the user's password.

then come back to workstation pc typing ctrl+D

Check the .ssh folder where ssh key be generated

ls -ls .ssh

Generate SSH key

Basically, there are multiple ways to generate ssh key, am using this method

ssh-keygen -t ed25519 -C 'mahesh default'

-t : type
ed25519 : is a more secure key more than the default key
-C : basically a comment

when you execute the key-gen command It will ask where to save it, let it be default folder. Hit enter It will ask to create a passphrase to key provide passphrase. after that your key will be generated in .ssh folder, you can check it and see two type file a private key & public key

ls -la .ssh

To see the content of the file

cat .ssh/id_ed25519.pub (for public key)

cat .ssh/id_ed25519 (for private key)

How do we use this key to connect our remote server?

The key can be uploaded to the .ssh folder of the remote server

ssh-copy-id -i ~/.ssh/id_ed25519.pub 192.168.43.60

type your remote default user password, and you can confirm it

ls -la .ssh

Connect remote server using newly created key

ssh 192.168.43.60

Now you will have to provide the passphrase used for creating SSH key, not the user password.

0 Komentar