LinuxでSSHパスワードなしのログインを設定する

LinuxでSSHパスワードなしのログインを設定する

次のURLのチュートリアルで提供されている手順を使用して、パスワードなしでリモートサーバーにログインするようにSSHを設定しました。 SSHパスワードなしログイン

sshコマンドのみを使用してサーバーにログインしようとすると、次のようになります。

$ ssh [email protected]

うまく動作し、パスワードを入力せずにログインできますが、scpコマンドを使用してローカルからリモートサーバーにファイルをコピーしようとすると、次のようになります。

$ scp /location/to/file/localserver user@server:location/whereto/copy

パスワードを尋ねるのは変です!

また、上記のURLで説明されているように、すべてのフォルダに正しい権限があることを確認しました。

この問題を解決する方法を知っている人はいますか?

Executing: program /usr/bin/ssh host *.*.*.*, user ssadmin, command scp -v -t /home/ssadmin/nexthink_log`

OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013`
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to *.*.*.* [*.*.*.*] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4* compat 0x00000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: kex: diffie-hellman-group-exchange-sha1 need=16 dh_need=16
debug1: kex: diffie-hellman-group-exchange-sha1 need=16 dh_need=16
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA **:**:**:**:**:**:**:**:**:**:**:**:**:**
debug1: Host '*.*.*.*' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password

ssadmin@*.*.*.*'s password:

ベストアンサー1

まず、Linux コンピュータにログインし、次のコマンドを使用して公開鍵ペアを生成します。

$ ssh-keygen -t rsa

パスワードの入力を求められたら、Enterキーを押します。

サーバーユーザーに.sshフォルダーを作成し、新しく生成された公開鍵(id_rsa.pub)をファイル名がauthorized_keysとしてPC上のユーザーの.sshディレクトリにアップロードします。

権限設定:

$ ssh [email protected] "chmod 700 .ssh; chmod 640 .ssh/authorized_keys" 

それだけです!

パスワードのないログインを安全に保護します。

おすすめ記事