SSH基础:启用调试模式确认连接过程

本文介绍了SSH的调试模式,通过 `-v` 选项详细展示连接步骤。首次连接时,会验证服务器指纹并提示确认,之后使用密钥或密码完成登录。后续连接则不再需要指纹确认。还讨论了如何设置密钥登录,使用 `ssh-copy-id` 或手动配置 `authorized_keys` 文件以实现无密码登录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
在ssh命令中可以通过-v选项直接开启调试模式,在连接的过程中将根据设定的调试等级输出对应的信息,这篇文章以确认ssh首次连接的动作为例,说明调试模式的使用方式。

调试模式

ssh命令中,调试模式有三种,具体说明如下所示:

类别 设定方法 使用示例 使用说明
调试模式1 -v ssh -v 具体命令 显示debug1的调试信息
调试模式2 -vv ssh -v 具体命令 显示debug1和debug2的调试信息
调试模式3 -vvv ssh -v 具体命令 显示debug1、debug2和debug3的调试信息

首次连接

比如在192.168.163.121这台机器上, 使用-v来确认连接的过程:

输入命令ssh -v 192.168.163.121

执行之前确认一下.ssh的密钥信息,可以看到有rsa的密钥对

[root@host121 ssh]# ls $HOME/.ssh
id_rsa  id_rsa.pub
[root@host121 ssh]#

执行信息如下所示:

[root@host121 ssh]# ssh -v 192.168.163.121
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 192.168.163.121 [192.168.163.121] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
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_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.163.121:22 as 'root'
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: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:y9ir2Jbc7kNZPhP9h/O9juUZbTmGDo6NZi2IZnLwg0s
The authenticity of host '192.168.163.121 (192.168.163.121)' can't be established.
ECDSA key fingerprint is SHA256:y9ir2Jbc7kNZPhP9h
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值