ssh server hardening
#/etc/ssh/sshd_config.d/10-hardening.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
PubkeyAuthentication yes
AllowUsers elias ansible
#/etc/ssh/sshd_config.d/10-hardening.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
PubkeyAuthentication yes
AllowUsers elias ansible
After rebooting a server, I couldn't SSH in until manually logging in on the device itself... everything changed when nmcli attacked:
sudo nmcli -f NAME,UUID,TYPE,DEVICE connection show # list connections; grab UUID
nmcli -g connection.permissions connection show <UUID> # if `user\:<user>`, restricted
sudo nmcli connection modify <UUID> connection.permissions ""
sudo nmcli connection modify <UUID> connection.autoconnect yes
to secure an SSH server:
from here
ssh-copy-id succeeds, but password still required to connect:To verify that the fingerprint of the local public key matches to a corresponding fingerprint in the remote ~/.ssh/authorized_keys file, run ssh-keygen -lf ~/.ssh/authorized_keys on the remote device, then ssh-keygen -lf ~/.ssh/id_<YOUR_KEY>.pub on the local device. There should be a match if ssh-copy-id succeeded.
The issue is not the key's content but the permissions of the key files. Those issues may exist on the remote or the local device.
This script (written by Claude) will assert standard SSH configuration permissions for necessary files:
#!/usr/bin/env bash
set -euo pipefail
ssh_dir="$HOME/.ssh"
if [[ ! -d "$ssh_dir" ]]; then
printf 'Error: %s does not exist\n' "$ssh_dir" >&2
exit 1
fi
chmod go-w "$HOME"
chmod 700 "$ssh_dir"
# Normalize ownership of the SSH directory and its contents.
chown -R "$(id -un):$(id -gn)" "$ssh_dir"
# Normalize common SSH authentication files if present.
for file in authorized_keys; do
if [[ -f "$ssh_dir/$file" ]]; then
chmod 600 "$ssh_dir/$file"
fi
done
printf 'SSH directory permissions normalized for %s\n' "$USER"