描述:我在Windows Pc和Raspberry Pi之间创建了ssh连接。为此,我遵循了以下步骤:
步骤1:以某种方式获取Raspberry Pi的IP地址。应该是这样的: 192.168.1.52
步骤2:打开外壳并通过ssh访问Raspberry Pi:
ssh pi@192.168.1.52你需要密码。
步骤3:在远程pc的主目录中使用以下命令:
mkdir .ssh步骤4:通过私钥/公钥保护ssh连接。在本地pc中,使用以下命令:
ssh-keygen -f .ssh/fede_windows -t rsa -b 4096如果您的本地机器是基于Linux的,请运行这一行:
chmod 600 .ssh/fede_windows # if linux最后:
scp .ssh/fede_windows.pub pi@192.168.1.52:.ssh步骤5:在远程pc中使用以下命令:
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 pi@192.168.1.52问题:当我再次在我的Ubuntu中通过生成一个名为fede_ubuntu的键来执行所有这些步骤时,无论我在命令中插入了什么,我似乎都能够执行Raspberry Pi:
ssh -i .ssh/fede_xyz pi@192.168.1.52它一直在工作,这是不应该发生的,因为它应该只限于我刚才创建的键。如果我切换到我的Windows机器,一切正常工作,只有当我指定正确的关键工作。
问:你能不能提出这个问题的可能原因,以及如何解决?
编辑:通过输入以下命令ssh -i .ssh/key_that_does_not_exits -v pi@192.168.1.52,我得到:
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: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com 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 no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com 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发布于 2021-08-22 16:11:11
命令cat ~/.ssh/fede_windows.pub >> ~/.ssh/authorized_keys将键附加到authorized_keys,它不会替换已经存在的内容。
若要替换所有旧密钥,请运行cat foobar.pub > ~/.ssh/authorized_keys。这将截断文件,然后添加新信息。
您可以添加任意数量的密钥。要检查,只需使用文本编辑器打开文件并查看内容。
拥有多个密钥的能力实际上是一项安全功能。这意味着您可以使用来自不同计算机的不同密钥,如果计算机丢失,您只需删除已损坏的密钥,而不是所有密钥。
https://askubuntu.com/questions/1359486
复制相似问题