Best practices:
Restrict SSH access to only those who require it for administrative purposes.
## /etc/ssh/sshd_config
AllowUsers username1 username2
Avoid using a common key pair for all users; instead, use individual user accounts.
Prefer public-key authentication over password authentication for increased security.
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
Disable password authentication if possible.
## /etc/ssh/sshd_config
PasswordAuthentication no
Regularly rotate SSH key pairs, especially for administrative accounts.
ssh-keygen
to generate strong key pairs.Disable direct root login via SSH.
## /etc/ssh/sshd_config
PermitRootLogin no
Use non-root user accounts and sudo for administrative tasks.
Change the default SSH port (typically 22) to a non-standard port.
## /etc/ssh/sshd_config
Port 2222 # Use a port of your choice
This can help mitigate automated attacks targeting the default port.
/etc/issue
file or use the Banner
directive in the SSH server configuration.Set an idle timeout to automatically disconnect idle SSH sessions.
## /etc/ssh/sshd_config
ClientAliveInterval 300
ClientAliveCountMax 0
Reduces the risk of unauthorized access if a user forgets to log out.
Integrate with system logging mechanisms.
## /etc/ssh/sshd_config
LogLevel VERBOSE
kubectl exec
for accessing containers.