Frequently Asked Question
How SSH Certificates and Passwords work
Last Updated 4 days ago
How SSH Certificates and Passwords work
SSH (Secure Shell) is a cryptographic network protocol that enables secure connections and data exchange between computers. It operates on port 22 by default but can be configured to use other ports as well. Below, we'll outline how SSH works, how certificate keys and passwords are used for authentication, and the configuration options in /etc/ssh/sshd_config needed for each method.
How SSH Works
- Connection Establishment:
- A client (such as a user's terminal) initiates an encrypted session with a server.
- Authentication Process:
- The server sends its public key to the client, allowing it to establish trust.
- Session Encryption:
- Once authenticated, data transmitted between the client and server is encrypted.
Using Password Authentication
- Client-Side Configuration:
- Ensure
PasswordAuthenticationis set toyesin/etc/ssh/sshd_config.
- Server-Side Configuration:
- Set
PermitRootLogin(if you allow root login) and possibly other user settings.
- Session Initiation:
- Enter your password when prompted by the SSH client.
Using Certificate Keys for Authentication
- Generate Key Pairs:
- Use
ssh-keygento generate public and private key pairs.
- Client-Side Configuration:
- Place the generated public key (
idrsa.pub) in the server's~/.ssh/authorizedkeysfile.
- Server-Side Configuration:
- Enable
PubkeyAuthenticationand setPasswordAuthenticationtonoin/etc/ssh/sshd_config.
- Session Initiation:
- SSH will use the key pair for authentication, prompting only for passphrase if set.
Mixed Authentication (Password and Certificate)
- Server-Side Configuration:
- Set both
PubkeyAuthenticationtoyesandPasswordAuthenticationtoyes.
- Client-Side Configuration:
- Ensure keys are correctly placed in the server's
~/.ssh/authorized_keys.
- Session Initiation:
- SSH will attempt key-based authentication first, falling back to password if necessary.
Relevant /etc/ssh/sshd_config Options
PasswordAuthentication yes
- PasswordAuthentication: Controls whether users can authenticate via passwords.
PubkeyAuthentication yes
- PubkeyAuthentication: Controls whether public key authentication is allowed.
PermitRootLogin prohibit-password
- PermitRootLogin: Specifies if root login is permitted. Can be set to
yes,no, or a specific user.
ChallengeResponseAuthentication no
- ChallengeResponseAuthentication: Allows the use of challenge-response authentication methods (like PAM).
Example Configuration for Mixed Authentication
PasswordAuthentication yes
PubkeyAuthentication yes
PermitRootLogin prohibit-password
Ensure you test your configuration changes thoroughly after modifying /etc/ssh/sshd_config to avoid lockouts or other issues.
By following these steps, you can effectively configure SSH for secure and flexible authentication methods in a UK-based IT environment.
