How can I configure key-based SSH login and block password logins, even for non-root users?

Linode Staff

I'd like to configure key-based logins for SSH access instead of password-based logins, possibly even for some or all non-root users. How can I accomplish this?

1 Reply

To get started with configuring key-based SSH logins, you'll want to start by generating an SSH key and installing it for each user who will be using key-based logins. We have instructions on how to do this in our Securing Your Server guide under Harden SSH access.

Once you've generated the key, you can disable password access for the root user, or any other user accounts. To disable password-based logins for all users, you can simply change PasswordAuthentication to no as described in SSH Daemon Options.

If you're looking to disable it selectively for some users and not for others, you might want to check out this ServerFault article which has an excellent suggestion on how to do this by matching certain users.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct