SSH公開鍵パスワードなしのログイン

SSH公開鍵パスワードなしのログイン

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設定も問題ありません(デフォルトでは拒否に設定されていると仮定)。あなたのシステム全体のセキュリティについては言及できません。

不足している内容がある場合はお知らせください。

おすすめ記事