비밀번호 없이 SSH Pub 키 로그인

비밀번호 없이 SSH Pub 키 로그인

Ubuntu 14.04.1 Server Edition에서 SSH 서버를 구성 중입니다. 목표는 공개 키 인증만 사용하고 특정 사용자 이름만 허용하는 것입니다.

내 공개 키와 개인 키가 생성되고 개인 키에 비밀번호가 설정됩니다. 공개 키를 서버에 복사했고(정확한 프로세스는 아래 설명) 이 명령을 사용하여 처음으로 서버에 SSH를 연결할 수 있었습니다.

ssh -i /path/to/id_rsa -p 50000 [email protected]

개인 키 비밀번호를 묻는 메시지가 표시되고 로그인이 허용되었습니다. 좋습니다.

그러나 SSH를 통해 서버에 다시 접속할 때마다 더 이상 개인 키 비밀번호를 묻는 메시지가 표시되지 않습니다. 다음과 같이 개인 키의 경로를 지정하지 않고도 로그인할 수도 있습니다.

ssh -p 50000 [email protected]

클라이언트(Mac OS X 10.8)에서 ~/.ssh/known_hosts를 삭제하고 다음을 통해 성공적으로 SSH를 통해 서버에 연결할 수도 있습니다.

ssh -p 50000 [email protected]

그래서 내 질문은 다음과 같습니다.

  1. 내 개인 키, 키의 비밀번호 또는 클라이언트의 ~/.ssh/known_hosts 내용을 사용하지 않는 경우 서버는 나를 인증하기 위해 무엇을 사용합니까?
  2. 내 SSH 서버가 안전하지 않습니까? 아래에 sshd_config 사본이 포함되어 있습니다.

당신의 도움을 주셔서 감사합니다.

키 생성 과정

- at your computer (not the server) do
    - generate the keys: ssh-keygen -t rsa -b 4096
        - public key is saved at ~/.ssh/id_rsa.pub
        - private key is saved at ~/.ssh/id_rsa
- copy id_rsa.pub to server and append to ~/.ssh/authorized_keys
    - ssh-copy-id username@remotehost
    - a more secure method is to copy via usb drive
        - make a backup: cp authorized_keys authorized_keys.original
        - add public key to file: cat id_rsa.pub >> authorized_keys
    - if your home directory is encrypted (mine is)
        - in sshd_config: AuthorizedKeysFile /etc/ssh/%u/authorized_keys
        - move the authorized_keys file to /etc/ssh/me/authorized_keys
            - mkdir /etc/ssh/me
                - chmod u=rwx,go= /etc/ssh/me
                - chown me /etc/ssh/me
            - mv ~/.ssh/authorized_keys /etc/ssh/me/authorized_keys
                - chmod u=rw,go= /etc/ssh/me/authorized_keys
                - chown me /etc/ssh/me/authorized_keys

sshd_config

# User modified sshd_config.
# See the sshd_config(5) manpage for details.


#### Networking options ####

# Listen on a non-standard port > 1024. Default is 22.
Port 50000

# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0

# Only use protocol version 2.
Protocol 2

X11Forwarding no
X11DisplayOffset 10

# Helps the server recognize problems and the connection will be killed.
TCPKeepAlive yes

#### Networking options ####


#### Key Configuration ####

# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Privilege Separation is turned on for security.
UsePrivilegeSeparation yes

# Use public key authentication
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
AuthorizedKeysFile /etc/ssh/%u/authorized_keys

#### Key Configuration ####


### Authentication ###

# 30 seconds to enter your key passphrase.
LoginGraceTime 30

# No root login.
PermitRootLogin no

# Force permissions checks on keyfiles and directories.
StrictModes yes

HostbasedAuthentication no

# Don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication.
IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED).
PermitEmptyPasswords no

# Disable challenge and response auth. Unnecessary when using keys.
ChallengeResponseAuthentication no

# Disable the use of passwords completly, only use public/private keys.
PasswordAuthentication no

# Using keys, no need for PAM (Pluggable Authentication Modules).
# Also allows SSHD to be run as a non-root user.
UsePAM no

# Don't use login(1)
UseLogin no

AllowUsers me

### Authentication ###


### Misc ###

# Logging
SyslogFacility AUTH
LogLevel VERBOSE

# Print the last time the user logged in.
PrintLastLog yes

# Maximum number of concurrent unauthenticated connections to the SSH daemon (the number of users still logging in).
MaxStartups 10:30:60

# Display login banner.
Banner /etc/issue.net

# Allow client to pass locale environment variables.
# Accept language variables to help the shell session display properly for the client.
AcceptEnv LANG LC_*

# External file transfer daemon to use for sftp requests.
Subsystem sftp /usr/lib/openssh/sftp-server

# Should the SSH daemon itself read and display the message of the day file.
PrintMotd no

### Misc ###

방화벽 구성

- allow incoming connections to port 50000
    - sudo ufw allow in 50000
- Rate-limit the connections
    For example, deny connections if an IP address has attempted to initiate
    6 or more connections in the last 30 seconds.
    - sudo ufw limit ssh

답변1

  1. 클라이언트 컴퓨터가 자격 증명을 캐시했을 가능성이 높으므로 여전히 개인 키를 사용하고 있을 가능성이 높습니다. 컴퓨터를 다시 시작하면 암호를 다시 입력해야 합니다. (또한 키가 에 있는 경우 해당 위치가 키를 확인하는 ~/.ssh/기본 위치입니다 .)ssh

  2. SSH 구성은 방화벽 설정과 마찬가지로 괜찮아 보입니다(기본값이 거부로 설정되어 있다고 가정). 나는 귀하 시스템의 보안에 대해 전체적으로 언급할 수 없습니다.

여기에 빠진 것이 있으면 알려주세요.

관련 정보