To enable private key authentication in the SSH daemon (`sshd`), 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. This will create a private key (`id_rsa`) and a public key (`id_rsa.pub`) in the `~/.ssh` directory.
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. This step adds your public key to the `authorized_keys` file on 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. **Optional: Disable Password Authentication** (recommended for enhanced security):
- Find the following line in `sshd_config` and set it to `no`:
PasswordAuthentication no
5. **Restart SSH Service**: Restart the SSH service to apply the changes.
sudo systemctl restart sshd
6. **Test Private 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
Private key authentication should now be enabled for your SSH server. Remember to keep your private key secure and do not share it with others.