Enable SSH public key authentication (2024)

This article describes the procedure to set up a Secure Shell (SSH) public key authentication.

  1. Log in to the server.

  2. Verify that the user exists:

    `getent passwd <username>`
  3. Look up the value assigned to the AuthorizedKeysFile parameter within
    /etc/ssh/sshd_config to determine the file where the key is stored:

     `grep AuthorizedKeysFile /etc/ssh/sshd_config`

    Note: The default location is ~/.ssh/authorized_keys within the
    user's default home directory.

  4. Switch to the user's home directory:

    `cd /directory-path`

    Note: Substitute directory-path with user's home directory path.

  5. Check permission levels for the .ssh/ directory. It should have 0700
    permissions and be owned by the user.

     `ls .ssh`

    a. If the directory does not exist, create it and set the permissions to 0700:

     `mkdir -m 700 .ssh`

    b. If the directory exists, you can set ownership separately:

     `chmod 700 .ssh/` `chown -R username:username /path/to/home/.ssh`
  6. Switch to .ssh/ directory and authorized_keys file:

    ```cd .ssh/vim authorized_keysll```
  7. Add the SSH Public Key to the end of the authorized_keys file:

    `vim authorized_keys`
  8. Change permissions to 600 and ensure proper ownership of the file:

    `chmod 600 authorized_keys``chown -R username:username authorized_keys`

Disable password authentication

If you want all users to log in with public keys and not passwords, you can disable password authentication.

Important: Disabling password authentication locks users who used a password
to access the server if SSH authentication is not configured for their account.

  1. Create a backup of the sshd_config file before making
    any changes:

    mkdir /home/username/backupcp /etc/ssh/sshd_config /home/username/backup/sshd_config.bak
  2. Open the sshd_config file:

    `vim /etc/ssh/sshd_config`
  3. Find the PubkeyAuthentication parameter and set it to yes. If the line is commented, remove any
    comment indicators (#).

  4. Find fthe PasswordAuthentication parameter within the same file and set it to no.

  5. Save the changes to the file and exit the file.

  6. Check the syntax by using sshd -t. If there are no errors, reload sshd:

    `service sshd reload`

Additional notes:

  1. The private key file on your local workstation (client-side) should have permissions set to
    600, and the .ssh directory should have the permissions set to 700. The
    authorized_keys files also work with 644 permissions, but 600 is
    more secure.

Updated 9 months ago

Enable SSH public key authentication (2024)
Top Articles
How to make a timeline in PowerPoint
US state-by-state AI legislation snapshot
Craigslist Home Health Care Jobs
Fat Hog Prices Today
Wordscapes Level 5130 Answers
Algebra Calculator Mathway
OSRS Fishing Training Guide: Quick Methods To Reach Level 99 - Rune Fanatics
Dr Doe's Chemistry Quiz Answer Key
Klustron 9
Miles City Montana Craigslist
Lenscrafters Westchester Mall
Wal-Mart 140 Supercenter Products
Wmlink/Sspr
Craigslist Free Grand Rapids
Driving Directions To Atlanta
MindWare : Customer Reviews : Hocus Pocus Magic Show Kit
Bestellung Ahrefs
Nissan Rogue Tire Size
WEB.DE Apps zum mailen auf dem SmartPhone, für Ihren Browser und Computer.
Strange World Showtimes Near Roxy Stadium 14
10 Fun Things to Do in Elk Grove, CA | Explore Elk Grove
Nhl Tankathon Mock Draft
Kamzz Llc
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
Evil Dead Rise Showtimes Near Regal Sawgrass & Imax
Manuela Qm Only
Delta Township Bsa
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Deepwoken: Best Attunement Tier List - Item Level Gaming
Devargasfuneral
Rund um die SIM-Karte | ALDI TALK
Upstate Ny Craigslist Pets
Hermann Memorial Urgent Care Near Me
7543460065
Gpa Calculator Georgia Tech
Mars Petcare 2037 American Italian Way Columbia Sc
Miracle Shoes Ff6
Gary Lezak Annual Salary
Top 25 E-Commerce Companies Using FedEx
Omaha Steaks Lava Cake Microwave Instructions
R/Moissanite
Puretalkusa.com/Amac
Kutty Movie Net
Dragon Ball Super Super Hero 123Movies
Blackwolf Run Pro Shop
Pink Runtz Strain, The Ultimate Guide
Yale College Confidential 2027
Centimeters to Feet conversion: cm to ft calculator
Wvu Workday
2000 Fortnite Symbols
Public Broadcasting Service Clg Wiki
Latest Posts
Article information

Author: Chrissy Homenick

Last Updated:

Views: 6487

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Chrissy Homenick

Birthday: 2001-10-22

Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

Phone: +96619177651654

Job: Mining Representative

Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.