Linux·28 questions

How to configure secure SSH key-based access and disable password login?

Answer

SSH key authentication is a reliable alternative to standard password login and protects the server from brute-force attacks. Generating a new key pair is performed on the local machine using the ssh-keygen utility, which creates public and private keys using the modern ed25519 cryptographic algorithm.

Transferring the public key to the remote server is done automatically using the ssh-copy-id utility. This command securely copies the contents of your public file to a special authorized_keys directory on the server with correct access permissions, which is critical for the mechanism to work.

The next step is to edit the global configuration file of the SSH daemon, which is located in the etcsshsshd_config directory. In this file, you need to find and modify authentication parameters, explicitly prohibiting password login and allowing access only using cryptographic keys.

The completion of the setup process is checking the syntax of the configuration file and restarting the sshd service in the operating system. Before closing the current terminal session, it is strongly recommended to open a new console window and make sure that a successful connection using the new key works correctly.

Was this answer helpful?

More questions in this topic

Related questions from other topics