비밀번호 액세스를 비활성화하고 개인 키를 통한 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
원격 호스트를 확인하세요.
구성이 잘못되었다고 생각하고 비밀번호나 키를 전혀 사용하지 않는 경우 SSH PubkeyAuthentication=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).