説明する

説明する

説明する

sshMS-Windows PCとRaspberry Piを接続しました。これを行うには、次の手順に従います。

ステップ1:Raspberry PiのIPアドレスを何とか取得します。次のようにする必要があります:192.168.1.52

ステップ2:シェルを開き、SSHを介してRaspberry Piにアクセスします。

ssh [email protected]

パスワードが必要です。

ステップ3:リモートコンピュータのホームディレクトリで次のコマンドを使用します。

mkdir .ssh

ステップ4:秘密鍵/公開鍵を介してSSH接続を保護します。ローカルコンピュータで次のコマンドを使用します。

ssh-keygen -f .ssh/fede_windows -t rsa -b 4096

ローカルコンピュータがLinuxベースの場合は、次の行を実行します。

chmod 600 .ssh/fede_windows # if linux

ついに:

scp .ssh/fede_windows.pub [email protected]:.ssh

ステップ5:リモートコンピュータで次のコマンドを使用します。

sudo nano /etc/ssh/sshd_config

そして、設定ファイルの次の行を修正します。

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

ついに:

sudo systemctl reload sshd

ステップ6:リモートコンピュータで次のコマンドを使用します。

cat ~/.ssh/fede_windows.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/*

ステップ7:ローカルコンピュータで次のコマンドを実行してリモートコンピュータにログインします。

ssh -i .ssh/fede_windows [email protected]

質問:Fede_ubuntuというキーを生成してUbuntu PCでこれらの手順をすべてやり直すと、コマンドに何を挿入してもRaspberry PiにSSHで接続できるように見えます。

ssh -i .ssh/fede_xyz [email protected]

これは常に機能し、作成したキーに制限する必要があるため、これは発生しないでください。 Windowsシステムに切り替えると、正しいキーを指定した場合にのみ、すべてが期待どおりに機能します。

質問:この問題の考えられる原因と解決策を提案できますか?

編集する: 次のコマンドを入力すると、次のようになります。ssh -i .ssh/key_that_does_not_exits -v [email protected]

Warning: Identity file .ssh/key_that_does_not_exits not accessible: No such file or directory.
OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.1.52 [192.168.1.52] port 22.
debug1: Connection established.
debug1: identity file /home/federico/.ssh/id_rsa type -1
debug1: identity file /home/federico/.ssh/id_rsa-cert type -1
debug1: identity file /home/federico/.ssh/id_dsa type -1
debug1: identity file /home/federico/.ssh/id_dsa-cert type -1
debug1: identity file /home/federico/.ssh/id_ecdsa type -1
debug1: identity file /home/federico/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/federico/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/federico/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/federico/.ssh/id_ed25519 type -1
debug1: identity file /home/federico/.ssh/id_ed25519-cert type -1
debug1: identity file /home/federico/.ssh/id_ed25519_sk type -1
debug1: identity file /home/federico/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/federico/.ssh/id_xmss type -1
debug1: identity file /home/federico/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Raspbian-10+deb10u2+rpt1
debug1: match: OpenSSH_7.9p1 Raspbian-10+deb10u2+rpt1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.52:22 as 'pi'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:hC5w2kDxgHH5eFRY1vOJaS7ipPR+8OWX2tkkEZbF194
debug1: Host '192.168.1.52' is known and matches the ECDSA host key.
debug1: Found key in /home/federico/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent
debug1: Will attempt key: /home/federico/.ssh/id_rsa 
debug1: Will attempt key: /home/federico/.ssh/id_dsa 
debug1: Will attempt key: /home/federico/.ssh/id_ecdsa 
debug1: Will attempt key: /home/federico/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/federico/.ssh/id_ed25519 
debug1: Will attempt key: /home/federico/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/federico/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent
debug1: Server accepts key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.1.52 ([192.168.1.52]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Remote: /home/pi/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /home/pi/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Sending environment.
debug1: Sending env LC_ADDRESS = it_IT.UTF-8
debug1: Sending env LC_NAME = it_IT.UTF-8
debug1: Sending env LC_MONETARY = it_IT.UTF-8
debug1: Sending env LC_PAPER = it_IT.UTF-8
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_IDENTIFICATION = it_IT.UTF-8
debug1: Sending env LC_TELEPHONE = it_IT.UTF-8
debug1: Sending env LC_MEASUREMENT = it_IT.UTF-8
debug1: Sending env LC_TIME = it_IT.UTF-8
debug1: Sending env LC_NUMERIC = it_IT.UTF-8
Last login: Sun Aug 22 22:26:00 2021 from 192.168.1.197

ベストアンサー1

ログから:

debug1: Next authentication method: publickey
debug1: Offering public key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent
debug1: Server accepts key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent
debug1: Authentication succeeded (publickey).

これは、SSH エージェントのキーが使用されていることを意味します。最近使用した有効なキーであり、エージェントに手動で追加したか、ファイルで使用するために追加したとしますAddKeysToAgent yes~/.ssh/config

SSHエージェントからすべてのIDを削除してもう一度やり直してくださいssh-add -D。またはIdentityAgent noneSSH設定に追加するか、ssh -o IndentityAgent=none呼び出し時に使用してくださいssh

IdentitiesOnly yesSSH設定でこれを使用すると、SSHサーバーに提供されるIDをより効果的に制御でき、利点を得ることができます。このオプションのマニュアルを参照してくださいssh_config(5)

おすすめ記事