AWS Simple Directory Service に対する SSHD の認証

AWS Simple Directory Service に対する SSHD の認証

AWS Simple Directory Service ディレクトリに対して公開キーを認証する sshd を備えた Centos 7 マシンのネットワークをセットアップしようとしています。

現在、私は Centos ホスト、Windows Server 2008 のインスタンス、および Amazon Web Service (AWS) Simple Directory Service を使用したディレクトリを所有しています。Windows ボックスはディレクトリの管理に使用され、Centos ボックスはディレクトリを使用して SSH セッションを認証します。すべてのマシンがディレクトリに参加しています。

単純なパスワード認証を使用して、ローカル ユーザーとドメイン ユーザーの両方として Centos ボックスに SSH 接続できることを確認しました。同様に、ローカル アカウントとドメイン アカウントの両方を使用して、単純なパスワード認証で Windows ボックスに RDP 接続できます。

しかし、私のディレクトリで AWS によって設定されたスキーマには、sshPublicKeyいわばすぐに使用できるフィールドを持つクラスは含まれていませんでした。

そこで、Windows ボックスの Active Directory スキーマ スナップインを使用して、次の属性をスキーマに追加しました。

Common Name: sshPublicKey
OOID: 1.3.6.1.4.1.24552.1.1.1.13
Syntax: IA5-String
Multi-valued: true

次に、次のクラスを作成しました。

Common Name: LDAP Public Key
OOID: 1.3.6.1.4.1.24552.500.1.1.2.0 
Parent Class: top
Class Type: Auxiliary
Optional Attributes: sshPublicKey

次に、ADSI スナップインを使用して、ユーザーの公開キーの内容をsshPublicKeyディレクトリ内のエントリのフィールドに追加しました。

私の Centos ボックスの 1 つで、PasswordAuthentication nosshd の設定ファイルを設定してパスワード認証を無効にしました。

次に、属性が設定されたディレクトリ ユーザーを使用して Centos ボックスに ssh で接続しようとしましたsshPublicKey

$ ssh -l [email protected] -i ~/.ssh/path.to.key.pub centos.box -vvv;
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/localuser/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to centos.box [ip addy] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "~/.ssh/path.to.key.pub" as a RSA1 public key
debug1: identity file ~/.ssh/path.to.key.pub type 1
debug1: identity file ~/.ssh/path.to.key.pub type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH*
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "centos.box" from file "/Users/localuser/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /Users/localuser/.ssh/known_hosts:someLineNumber
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],ssh-rsa,[email protected],[email protected],ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ecdsa-sha2-nistp256
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: mac_setup: found [email protected]
debug1: kex: server->client aes128-ctr [email protected] none
debug2: mac_setup: found [email protected]
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 116/256
debug2: bits set: 535/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA blah
debug3: load_hostkeys: loading entries for host "centos.box" from file "/Users/localuser/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /Users/localuser/.ssh/known_hosts:someLine
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'centos.box' is known and matches the RSA host key.
debug1: Found key in /Users/localuser/.ssh/known_hosts:27
debug2: bits set: 509/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/localuser/.ssh/path.to.key.pub (0x7fb3cb600000), explicit
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/localuser/.ssh/path.to.key.pub
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
$

Centos ボックスでは、次のようになります。

$ sudo journalctl -felu sshd
....
Some Date centos.box sshd[a number]: Connection closed by 1.2.3.4 [preauth]

秘密鍵の権限は600、公開鍵の権限は644

ディレクトリ サービス ホスト上のサーバー ログを確認する方法がわかりません。

何が間違っているのか、何かアイデアはありますか?

答え1

sshd公開鍵認証のためにが通信していることを確認するにはsssd、ホストで次の手順を実行しますsshd

  1. [sssd]ファイルのセクションに次の行を追加します/etc/sssd/sssd.conf

    services = ssh, [ all the other services already listed there as well ]
    

これはsssdと通信する必要があることを指示しますsshd

  1. そこにまだセクションがない場合は[ssh]、ファイル[ssh]に空のセクションを追加します/etc/sssd/sssd.conf

    [ssh]
    

これは、通信するすべてのサービスに必要な構成セクションですsssd

  1. [domain/directory.server]ファイルの セクションに次の行を追加します/etc/sssd/sssd.conf。 はdirectory.serverディレクトリ サービス ホストの完全修飾ドメイン名です。

    ldap_user_ssh_public_key = sshPublicKey
    

これは、ユーザーの公開 SSH キーsssdを見つけるために使用する属性を指定します。(sshdで使用されるデフォルトの属性は でsssdあり、これはおよびクラスipaSshPubKeyのスキーマにあります。ipaSshUseripaSshHost

  1. ファイルに次の行を追加します/etc/sshd/sshd_config

    AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys
    AuthorizedKeysCommandUser nobody
    

これは、ユーザーとしてsshdファイルを実行するように指示します。 ホストへの認証を試行するユーザーの承認済みキーを取得します。/usr/bin/sss_ssh_authorizedkeysnobody/usr/bin/sss_ssh_authorizedkeyssshd

  1. ファイルに次の行を追加します/etc/sshd/ssh_config

    GlobalKnownHostsFile /var/lib/sss/pubconf/known_hosts
    ProxyCommand /usr/bin/sss_ssh_knownhostsproxy -p %p %h
    

これは、sssdクライアントの名前と公開鍵を に追加し/var/lib/sss/pubconf/known_hosts、クライアントに接続し、実行可能ファイル を使用して、すべての通信を標準 I/O 経由でパイプするように指示します/usr/bin/sss_ssh_knownhostsproxy

  1. 両方のサービスを再起動します。

    $ sudo systemctl reload sshd;
    $ sudo systemctl restart sshd;
    $ sudo systemctl restart sssd;
    

関連情報