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 Linux

How to Set Up SSH Keys on Debian

by Cloudbooklet
2 years ago
in Linux
How To Set Up Ssh Keys On Debian
ShareTweetSendShare
ADVERTISEMENT

There are 2 methods to access the SSH, one is by password based and other is key based. The SSH key based authentication is meant provide a secure way to access a server with private and public key.

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

  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

You can skip this if you already have created the user.

ADVERTISEMENT

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

You might also like

Symbolic Links In Linux

Symbolic Links in Linux: What They Are and How to Use Them

2 months ago
Ubuntu Password

Reset your Forgotten Ubuntu Password in 2 Minutes

3 months ago
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.

Grant sudo access to new user

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

ADVERTISEMENT
sudo usermod -aG sudo username

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

Step 2: Disable Password Authentication for User

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

ADVERTISEMENT
sudo nano /etc/ssh/sshd_config

Add the following to the last.

Match User username
    PasswordAuthentication no

Save the file and restart SSH.

ADVERTISEMENT
sudo systemctl restart ssh

Now the user cannot login using password.

Step 3: Generate SSH Key

Login as the user you have created above.

ADVERTISEMENT
sudo su username

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

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: DebianSecurity
Share4Tweet3SendShare
Cloudbooklet

Cloudbooklet

Leave a Reply Cancel reply

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

Related Posts

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago
Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago

Follow Us

Trending Articles

Spotify Supremium_11Zon

Spotify Supremium: Everything You Need to Know About the New HiFi Tier

September 26, 2023

Top 10 Ways to Use ChatGPT for Marketing in 2023

5 AI Tools for Business Owners to Make Their Life Easier

AI Powered 3D Models to Create 3D Designs in Breeze

5 Best Laptop for Minecraft in 2023: Top Picks for All Budgets

Interactive AI – Next Phase of Artificial Intelligence

Popular Articles

Birthday Posts On Facebook

How to See all my Birthday Posts on Facebook

September 22, 2023

Microsoft Bing AI Image Generator: How to Create Amazing Artworks with AI

How to Create ZIP File on Android: A Smart and Easy Way

Create High Quality AI Cover Song with Covers AI

Microsoft Editor vs Grammarly: Which is the Best Grammar Checker?

7 Ways to See if Someone Blocked You on Telegram

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.