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
What happens if my package from eBay gets stolen?
Do Testers have to Write Code?
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
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.