O'Reilly logo

Ubuntu Server Cookbook by Uday R. Sawant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up public key authentication

In this recipe, you will see how to set up secure public key authentication.

Getting ready

You might need root privileges for certain tasks.

How to do it...

Follow these steps to set up public key authentication:

  1. Add a new user. You can skip this step if you have already created a user:
    $sudo adduser john
    
  2. Log in as john and change to the home directory with cd ~/:
  3. Create a .ssh directory if it doesn't already exist:
    $ mkdir .ssh
    
  4. Create a file named authorized_keys under the .ssh directory:
    $ touch .ssh/authorized_keys
    
  5. Set permissions on the .ssh directory to 700:
    $chmod 700 .ssh
    
  6. Set permissions for authorized_keys to 600:
    $ chmod 600 .ssh/authorized_keys
    
  7. Generate public key pair on your local system with the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required