Restricting remote access with key-based login into SSH

Even though SSH login is protected by using passwords for the user account, we can make it more secure by using key-based authentication into SSH.

Getting ready

To see how key-based authentication works, we will need two Linux systems (in our example, both our Ubuntu systems). One should have the OpenSSH server package installed on it.

How to do it...

To use key-based authentication, we need to create a pair of keys­—a private key and a public key.

  1. On the client or local system, we will execute the following command to generate the SSH key-pair:
    ssh-keygen-t rsa
    • The output obtained will be as follows:
  2. While creating the key, we can accept the default values or change them as per our wishes. It will ...

Get Practical Linux Security Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.