パスワードアクセスを無効にし、秘密鍵を介したSSH接続のみを許可して、パイをより安全にしようとしています。理由はわかりませんが、たとえばkeyなしでpiにアクセスしようとするとssh ubuntu@myip
機能します。
私のパイにSSHで接続する唯一の方法は、秘密鍵を次のように使用することです。
ssh ubuntu@ip -i ./.ssh/the_key
秘密鍵を使用せずにまだアクセスできるのはなぜですか?PasswordAuthentication no
、などを追加するなどの明白な手順を試しましたChallengeResponseAuthentication no
。PubkeyAuthentication yes
また、キーにキーフレーズを追加しました。キーを介してsshするときは一度だけ要求しましたが、もう要求しません。なぜそのようなことが起こるのかよくわかりません。
私の/etc/ssh/sshd_configファイル:
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowUsers root otheruser
#PermitRootLogin without-password
PubkeyAuthentication yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
ありがとう
答え1
同様のものを使用する場合は、ssh-copy-id
キーを指定する必要はありません。すべてがあなたのために処理されました。例:
[root@paw .ssh]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'stig.example.com (<no hostip for proxy command>)' can't be established.
ECDSA key fingerprint is SHA256:of39GMe8Hq+x8LylBcVvaKwaQYUnyS5+2Oi+jY8IU1Y.
ECDSA key fingerprint is MD5:a9:48:f6:0d:eb:1e:e2:11:55:dc:16:6e:c6:8f:5e:b8.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[root@paw .ssh]# ssh [email protected]
Last login: Sat Aug 28 07:26:05 2021 from 172.16.0.8
[root@stig ~]#
自分のキーのみが使用されていることを確認するには、authorized_keys
リモートホストを確認してください。
設定が間違っていると考え、パスワードやキーをまったく使用しない場合は、SSHPubkeyAuthentication=no
オプションを使用して次のことを確認できます。
[root@paw .ssh]# ssh -o PubkeyAuthentication=no stig.example.com
[email protected]'s password:
Last login: Sat Aug 28 07:27:18 2021 from 172.16.0.8
[root@stig ~]#
それ以外の場合は、ssh -v user@host
次の行を使用して見つけることができますAuthentications that can continue
。
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).