SSH-copy-id에 대한 노트북의 pubkey를 사용하여 SSH 서버에 로컬로 연결할 수 없습니다

SSH-copy-id에 대한 노트북의 pubkey를 사용하여 SSH 서버에 로컬로 연결할 수 없습니다

나는 여기서 내가 어디로 잘못 가고 있는지 평생 알 수 없으며 내 실수를 지적하기 위해 다른 눈이 필요합니다. ufw가 지정된 SSH 포트를 여는 방식으로 내 아치 데스크탑에서 로컬로 sshd 서비스를 실행하고 있습니다.

비밀번호 인증을 활성화하면 작동하지만 ssh-copy-id. 공개 키로 전환하면 sshd_config연결이 거부됩니다.

디버그 ssh [insert additional commands] -vvv데이터는 머신에 아직 내 공개 키가 없다는 것을 확인하지만 로컬 네트워크를 통해 실행하면 설치해야 할 키 1개가 남아 있고 키를 설치하라는 메시지가 표시되면 키를 설치하라는 메시지가 표시됩니다. 연결을 거부합니다.ssh-copy-id -p 31221 -i ~/.ssh/ed25519key.pub [email protected]

내 ufw 규칙에 따르면 특정 IP 주소는 내가 제거하려고 마지막으로 시도한 것이었지만 전체 시간 동안 거기에 있었던 것은 아닙니다.

[john@thedream ssh]$ sudo ufw status
[sudo] password for john:
Status: active

To                         Action      From
--                         ------      ----
WWW Full                   ALLOW       Anywhere
31221                      ALLOW       192.168.1.0/24
31221                      ALLOW       192.168.1.251
WWW Full (v6)              ALLOW       Anywhere (v6)

내 sshd_config

#   $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/bin

# 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.

#Port 22
Port 31221
#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 no
#StrictModes yes
#MaxAuthTries 50
#MaxSessions 10

PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile  .ssh/authorized_keys

#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
AuthenticationMethods publickey
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
KbdInteractiveAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication yes
#GSSAPICleanupCredentials 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 KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM 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 /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem   sftp    /usr/lib/ssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   PermitTTY no
#   ForceCommand cvs server

내 SSHD 서비스가 실행 중입니다

[john@thedream ssh]$ sudo systemctl status sshd
● sshd.service - OpenSSH Daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: disabled)
     Active: active (running) since Tue 2023-02-21 18:02:28 CST; 2s ago
   Main PID: 9451 (sshd)
      Tasks: 1 (limit: 38319)
     Memory: 1.1M
        CPU: 4ms
     CGroup: /system.slice/sshd.service
             └─9451 "sshd: /usr/bin/sshd -D [listener] 0 of 10-100 startups"

Feb 21 18:02:28 thedream systemd[1]: Started OpenSSH Daemon.
Feb 21 18:02:28 thedream sshd[9451]: Server listening on 0.0.0.0 port 31221.
Feb 21 18:02:28 thedream sshd[9451]: Server listening on :: port 31221.

그리고 내 포트 31221이 열려 있습니다.

[john@thedream ssh]$ sudo lsof -i:31221
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd    9451 root    3u  IPv4  88455      0t0  TCP *:31221 (LISTEN)
sshd    9451 root    4u  IPv6  88457      0t0  TCP *:31221 (LISTEN)

답변1

그래서 내가 찾을 수 있는 한, ssh-copy-id를 PasswordAuthenticationset 으로만 사용할 수 있다는 것이 밝혀졌습니다 .yes

매뉴얼 페이지 에서 인용 ssh-copy-id: (presumably using a login password, so password authentication should be enabled, unless you've done some clever use of multiple identities)

주의할 점은 다중 ID 설정이 있고 그 중 하나가 이미 서버에 저장된 공개 키를 가지고 있는 경우 이를 정직하게 설정하는 방법이나 추가 단계가 필요한지 확실하지 않지만 충분히 쉬울 것이라고 믿습니다. 다른 서비스와 마찬가지로 클라이언트 측 SSH 구성을 사용합니다.

이전에 비밀번호 인증을 활성화한 상태에서 뭔가를 엉망으로 만들었던 것 같은데 파악하지 못했습니다.

해상도는 다음과 같습니다.

  1. 호스트 시스템에서 sshd를 사용하여 기본이지만 안전한 SSH 서버 설정
  2. 그런 다음 클라이언트에서 키 쌍을 생성하고 ssh-copy-id공개 키를 서버에 푸시하는 데 사용합니다.
  3. 그런 다음 서버의 sshd_config에서 비밀번호 인증을 비활성화하십시오.
  4. 마지막으로 동일한 구성에서 공개 키 인증 옵션을 활성화합니다.

기본으로 돌아가서 잘 작동하는 것 같습니다.

관련 정보