Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

How to Setup SSH Keys on Ubuntu 20.04

by Cloudbooklet
4 months ago
in Google Cloud, AWS
How To Setup Ssh Keys On Ubuntu
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

SSH keys provide a secure way for logging to a server with private and public key-based authentications. Read the article the setup SSH keys on ubuntu 20.04.

ADVERTISEMENT

SSH keys provide a secure way for logging to a server with private and public key based authentications.

In this guide you are going to learn the following ways to secure your server.

  1. Create new user with sudo privileges
  2. Disable password based auth
  3. Generate SSH Keys
  4. Configure SSH key for the user
  5. Disable password prompt while using sudo

Step 1: Create New User

Create a new user with password disabled using the following command.

ADVERTISEMENT
sudo adduser username --disabled-password

Follow the prompts and confirm with Y, which creates the user with the user’s home directory in /home/username.

You might also like

How To Install Git On Ubuntu 20.04

How to Install Git on Linux

3 months ago
Vector Image

DataStax Enhances Astra DB on Google Cloud with Vector Search Capability

3 months ago

Grant sudo access to new user

Add the new user to the sudo group so the user will have admin privileges to run commands.

sudo usermod -aG sudo username

Now you have a new user with sudo rights and password disabled.

ADVERTISEMENT

Step 2: Disable Password Authentication for User

Edit the /etc/ssh/sshd_config file to configure authentication.

sudo nano /etc/ssh/sshd_config

Add the following to the last.

ADVERTISEMENT
Match User username
    PasswordAuthentication no

Save the file and restart SSH.

sudo systemctl restart ssh

Now the user cannot login using password.

ADVERTISEMENT

Step 3: Generate SSH Key

Login as the user you have created above.

sudo su username

Create new .ssh directory to hold the ssh keys and navigate into it.

ADVERTISEMENT

Don’t use sudo inside here.

mkdir .ssh
cd .ssh

Create SSH Keys.

ssh-keygen -m PEM -t rsa -b 4096 -C "your_email"

Here I have used to PEM format to generate RSA based key. If the -m PEM is removed it might generate OpenSSH key.

When prompted provide the name for the key.

Skip passphrase and complete the setup.

Now you should have 2 files inside your .ssh directory.

filename.pub
filename

The filename.pub is your public key and filename is your private key.

Step 4: Configure SSH key for SSH access.

To allow SSH connection you need to add the public key to the authorized_keys file.

cat filename.pub >> authorized_keys

This command will create a file named authorized_keys and add the content of public key to it.

Copy the content of private key, you can make authentication to the server using this.

cat filename

This command outputs the content of your private key. Save it for auth.

Step 5: Disable Password prompt while using sudo

By default when you run sudo based commands with other user the system prompts to enter the password for the user.

As we don’t use password we need to disable it.

Exit the user shell and get back to your root shell.

Execute the command to enter visudo.

sudo visudo

Add the following to the last.

username ALL=(ALL) NOPASSWD: ALL

Save the file and exit.

That’s it. Now you have a user who can login only using SSH keys.

Tags: SecurityUbuntuUbuntu 20.04
Share2Tweet1SendShare
Cloudbooklet

Cloudbooklet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago
Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Wix Ai

Create a Professional Website with Wix AI Website Builder

September 19, 2023

10 Best AI Song Generator in 2023 (Free and Paid)

5 FREE AI Horoscope Online – Personalized Way to See Your Future

7 Best Lyric Video Maker Software for Music Lovers

How to Delete Netflix Account Permanently

Microsoft Unveils New Disc-Less Xbox Series X with Lift-to-Wake Controller

Popular Articles

Ai Video Editor

7 Best AI Video Editor Tools for Creating Amazing Videos

September 13, 2023

Top 5 Free Linux Cloud Servers to Host Your Website

Google Safe Search Settings: Blurred Explicit Images in Search Results

Quantum AI Trading: The Future of Trading

Jenni AI: How to Use AI Writing Assistant for Amazing Content

Top 5 AI Jewellery Generators to Create Jewellery Designs

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.