![如何在我的服务器上设置 SSH 密钥](https://linux22.com/image/1088844/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%88%91%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E8%AE%BE%E7%BD%AE%20SSH%20%E5%AF%86%E9%92%A5.png)
我尝试设置密码来使用 ubuntu server 16.04 访问我的服务器
这是我所做的(抱歉,评论不是英文的):
Sécuriser SSH :
Créer 1 administrateur
# adduser admin962
L’ajouter aux groupes sudo et ssh
# adduser admin962 sudo
# adduser admin962 ssh
Modifier la configuration de SSH (interdire root, modifier le port et autoriser uniquement le groupe sudo)
# nano /etc/ssh/sshd_config
AllowGroups sudo
Port 4029
RSAAuthentication yes
PubkeyAuthentication yes
décommenter AuthorizedKeysFile
Redémarrer le service SSH
# service ssh restart
Se déconnecter
# exit
Créer un jeu de clés (clé publique et clé privée) sur le client
$ ssh-keygen -t rsa -b 4096 -C admin962@vps307796
Faire entrée et choisir la passphrase
Copier la clé publique du client sur le serveur
$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] -p 4029
Se connecter avec admin962 et saisir le mot de passe (tester avec une nouvelle fenêtre)
$ ssh [email protected] -p 4029
Droits des dossiers
$ chmod go-w ~/
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
$ ssh-add
Recharger le service SSH
$ sudo service sshd reload
Se déconnecter
# exit
Se connecter avec admin962 et saisir la passphrase (tester avec une nouvelle fenêtre)
$ ssh [email protected] -p 4029
Modifier la configuration de SSH (refuser les mots de passe)
$ sudo nano /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
UsePAM no
Redémarrer le service SSH
$ service ssh restart
Se connecter avec admin962 et saisir la passphrase
$ ssh [email protected] -p 4029
按照上述步骤,当我连接时会出现以下消息:
Agent admitted failure to sign using the key.
Permission denied (publickey).
详细信息:
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to vps307796.ovh.net [137.74.174.65] port 4029.
debug1: Connection established.
debug1: identity file /home/phablet/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/phablet/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Ubuntu-5ubuntu1.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 3f:a2:b6:45:3c:9b:e5:f8:e1:53:fb:fb:8c:21:46:52
debug1: Host 'vps307796.ovh.net' is known and matches the ECDSA host key.
debug1: Found key in /home/phablet/.ssh/known_hosts:1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/phablet/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
Agent admitted failure to sign using the key.
debug1: Offering RSA public key: admin462@vps307796
debug1: Server accepts key: pkalg ssh-rsa blen 535
Agent admitted failure to sign using the key.
debug1: Trying private key: /home/phablet/.ssh/id_dsa
debug1: Trying private key: /home/phablet/.ssh/id_ecdsa
debug1: Trying private key: /home/phablet/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).