۱. کلید روی سرور
از رایانهی خود (اگر کلید ندارید ابتدا ssh-keygen -t ed25519 بزنید):
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@192.168.10.21۲. پیکربندی
sudo nano /etc/ssh/sshd_config.d/10-hardening.confPermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey
MaxAuthTries 3
LoginGraceTime 30
ClientAliveInterval 300
ClientAliveCountMax 2
AllowGroups sshusers
X11Forwarding noAllowGroups فقط اعضای گروه sshusers را راه میدهد. پیش از اعمال، خودتان را به آن اضافه کنید:
sudo groupadd -f sshusers
sudo usermod -aG sshusers admin۳. الگوریتمهای مدرن
sudo nano /etc/ssh/sshd_config.d/20-crypto.confKexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com۴. اعمال و آزمایش
sudo sshd -t && sudo systemctl reload sshنشست فعلی را نبندید و از ترمینال دیگری وارد شوید. بعد بررسی کنید که ورود با رمز رد میشود:
ssh -o PubkeyAuthentication=no admin@192.168.10.21پیام Permission denied (publickey) یعنی همهچیز درست است.