To enable public key authentication in the SSH daemon (`sshd`), you need to follow these steps:
1. **Generate SSH Key Pair**: If you haven't already, generate an SSH key pair on the client machine. You can do this with the `ssh-keygen` command.
ssh-keygen -t rsa -b 4096
Follow the prompts to generate the key pair.
2. **Copy the Public Key to the Server**: Use `ssh-copy-id` to copy your public key to the server. Replace `username` and `server_ip` with your actual username and server IP address.
ssh-copy-id username@server_ip
You'll be prompted to enter your password for the server.
3. **Modify SSHD Configuration**: Edit the SSH daemon configuration file (`sshd_config`). This file is usually located in `/etc/ssh/sshd_config`. Find the following line and ensure it is set to `yes`:
PubkeyAuthentication yes
If the line is commented out (`#PubkeyAuthentication yes`), remove the `#` at the beginning.
4. **Restart SSH Service**: Restart the SSH service to apply the changes.
sudo systemctl restart sshd
5. **Test Public Key Authentication**: Try to SSH into the server from the client machine. If everything is set up correctly, you should be logged in without needing to enter a password.
ssh username@server_ip
That's it! Public key authentication should now be enabled for your SSH server.