在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/O9juUZbTmGDo6NZi2IZnLwg0s.
ECDSA key fingerprint is MD5:d5:e7:dc:b3:21:06:5a:e5:c0:f7:a4:60:f7:59:d4:48.
Are you sure you want to continue connecting (yes/no)?

可以看到开始登录时会确认 /root/.ssh/id_rsa的信息,并返回了存在的信息,在输入known_hosts之前,确认了服务器的密钥指纹信息,并提示用户是否继续

输入yes继续确认

输入yes之后,可以看到试图使用密钥方式进行登录的过程,ssh支持密钥方式登录和用户名/密码登录等两种方式,数据传输的安全性都是可以得到保证的,不同在于是否需要输入密码。

Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.163.121' (ECDSA) to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
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: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
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
root@192.168.163.121's password:

此时在别的终端已经可以确认此时已经生成了know_hosts的信息,这是上一步骤中yes输入之后的结果。

[root@host121 ~]# ls ~/.ssh
id_rsa  id_rsa.pub  known_hosts
[root@host121 ~]# cat ~/.ssh/known_hosts
192.168.163.121 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEy3w5004yyzNA8dXo1vo67E63tZybV88SiDupDfnHzHCeZ4tHjNqdabc9Fa+Jwwe5uIjcUFb+Ag4HaBjK4982U=
[root@host121 ~]#

输入密码完成登录

输入密码之后即可完成登录

root@192.168.163.121's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.163.121 ([192.168.163.121]: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: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
Last login: Sat Dec  7 18:48:33 2019 from gateway
[root@host121 ~]#

首次之后的连接

首次之后的连接,不再需要确认know_hosts的信息,使用-v确认结果如下所示

[root@host121 ~]# 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
debug1: Host '192.168.163.121' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
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: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
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
root@192.168.163.121's password:
debug1: Authentication succeeded (password).
Authenticated to 192.168.163.121 ([192.168.163.121]: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: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
Last login: Sat Dec  7 19:46:25 2019 from host121
[root@host121 ~]#

密钥登录方式

ssh连接设定

SSH在使用中,更多的使用则是使用密钥方式登录,首先使用ssh-copy-id设定登录,本示例中是本机连接本机,但是方式都是相同的。

[root@host121 ~]# ls ~/.ssh
id_rsa  id_rsa.pub  known_hosts
[root@host121 ~]# ssh-copy-id -i 192.168.163.121
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.163.121's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh '192.168.163.121'"
and check to make sure that only the key(s) you wanted were added.[root@host121 ~]#
[root@host121 ~]# ls ~/.ssh
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[root@host121 ~]# cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCj7f9fLXrbmXCXvdjlKwgJhDZ7VNr8eT++j3elmJq2SmVAPKT2Ows8Xjtrvsik9p7dTCwX6B88VUTTBdAQJCoADTxUIcn847XCkLSz5803d4spR3fVaZl6U+VEvW6fDnTAPUzuWpb2E/lBIVr9x8p1hayZFHtODrKPzyDp1li3fu6F+NR1gVsbiuYIyKH8QJIL1P2QYiyGn0/+qfaJAJ9QvbqmCCnJLhbrfBeFb4e/K+66guctaHc7qPXaeA98kJhKZg5ZqlHY+jC7F4T+/zp/bwophcnk67HakVju++R44zJdGVercZNkHZdMNWfMiwF4Xkt7uT/SEMaLUvWd+3UT root@host121
[root@host121 ~]# ls -l ~/.ssh
total 16
-rw-------. 1 root root  394 Dec  7 19:51 authorized_keys
-rw-------. 1 root root 1679 Dec  7 16:46 id_rsa
-rw-r--r--. 1 root root  394 Dec  7 16:46 id_rsa.pub
-rw-r--r--. 1 root root  177 Dec  7 19:36 known_hosts
[root@host121 ~]#

当然手动设定也是一样,主要在于authorized_keys文件以及其600的权限需要注意。此文件需要设定在目标机器上。

连接过程确认

[root@host121 ~]# 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
debug1: Host '192.168.163.121' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
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: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.163.121 ([192.168.163.121]: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: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
Last login: Sat Dec  7 19:48:37 2019 from host121
[root@host121 ~]#

从上述信息中可以看到,由于通过ssh-copy-id进行了ssh密钥设定,所以在证书认证阶段就已经成果,所以没有再有后面的Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password通过密码方式登录的提示信息了流程了。

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

  1. 华为手机打开调试模式adb连接电脑的方法

    https://club.huawei.com/thread-15094024-1-1.html 做android客户端开发,需要用真机测试.但是EMUI5.1很难连接上电脑. 经过一番研究,终于找到 ...

  2. Linux 中启用 Shell 脚本的调试模式

    shell 脚本调试系列 Linux 中启用 Shell 脚本的调试模式 在 Shell 脚本中执行语法检查调试模式 在 Shell 脚本中跟踪调试命令的执行 概述 脚本是存储在一个文件的一系列命令. ...

  3. 如何在 Linux 中启用 Shell 脚本的调试模式

    脚本是存储在一个文件的一系列命令.在终端上输入一个个命令,按顺序执行的方法太弱了,使用脚本,系统中的用户可以在一个文件中存储所有命令,反复调用该文件多次重新执行命令. 在学习脚本或写脚本的初期阶段,我 ...

  4. 大神教你如何在 Linux 中启用 Shell 脚本的调试模式

    导读 脚本是存储在一个文件的一系列命令.在终端上输入一个个命令,按顺序执行的方法太弱了,使用脚本,系统中的用户可以在一个文件中存储所有命令,反复调用该文件多次重新执行命令. 在学习脚本或写脚本的初期阶 ...

  5. 如何启用nodejs request模块的调试模式

    nodejs里的request module是一个进行HTTP通讯非常好用的库,最近查看它的源代码,发现一个有用的调试模式. 第134行, 把nodejs当前的环境变量NODE_DEBUG的值写入Re ...

  6. 如何在 Shell 脚本中执行语法检查调试模式

    我们开启了 Shell 脚本调试系列文章,先是解释了不同的调试选项,下面介绍如何启用shell调试模式. 写完脚本后,建议在运行脚本之前先检查脚本中的语法,而不是查看它们的输出以确认它们是否正常工作. ...

  7. 在 Shell 脚本中执行语法检查调试模式

    文章目录 shell 脚本调试系列 概述 启用 verbose 调试模式 在 Shell 脚本中启用语法检查调试模式 通过修改脚本的首行来启用脚本检查 内置的 set 命令来在脚本中启用调试模式 sh ...

  8. SSH自动输入密码,取消首次连接确认

    SSH是最常用的工具了,ssh username@ipAddress 即发起到远程主机的访问.随后输入远程机器的密码即可连接,同时,首次连接到远程主机还会要求获得远程主机的公钥,这时必须手动输&quo ...

  9. android机上没有usb调试模式吗,如何在Android上启用USB调试

    Android系统的手机以及平板电脑占有巨大的市场份额,当使用USB数据线完成电脑端与安卓手机端数据传输时,需要将安卓手机开启USB调试模式. 什么是USB调试?USB调试是一种模式,允许Androi ...

最新文章

  1. oculus rift 开发入门
  2. python微信开发实例 pdf 百度网盘_用python看女神微信里的百度云资源有啥?
  3. (7) ebj学习: jpa 一对一,一对多,多对多
  4. 网络 IO 演变过程
  5. Ruby如何成长成高性能系统构架
  6. 第一篇:Spring Boot 快速入门篇
  7. opencv java水平投影_使用OpenCv中Mat进行水平投影与垂直投影并实现字符切分
  8. python每日一题今天的答案_python每日一题总结1
  9. [2018.08.09 T1] 数学题
  10. 什么是索引?怎么创建索引?索引的使用原则?
  11. 公摊面积用计算机怎么计算,公摊面积计算(公摊面积计算器)
  12. 雷达系统概述--距离分辨率
  13. js中math常用使用方法
  14. B016 - 基于51单片机的公交车语音报站_点阵广告屏
  15. java开发工程师面试自我介绍_Java程序员自我介绍
  16. 对有序表进行折半查找的非递归算法
  17. 随机数字信号处理实验报告三——Levinson和Burg递推法MATLAB实现
  18. java-IO流(2)-字节流和字符流的介绍
  19. 软件测试方法和技术实验-佣金问题
  20. [附源码]java毕业设计书店网站论文

热门文章

  1. 前后端交互 - JWT鉴权到底是何方神圣
  2. C语言判断文件所在路径和目录是否存在,不存在则创建
  3. 计算机屏幕亮度调到多少合适,一般显示器的亮度对比度调到多少比较好啊(0 – 手机爱问...
  4. 免费logo创建器launchaco
  5. 问卷工具选择要看哪些方面?
  6. poi读取excel工具类
  7. 50首经典好听的英文歌曲![转]
  8. [附源码]JSP+ssm计算机毕业设计小学生作业帮平台的设计与实现0in3j【源码、数据库、LW、部署】
  9. 宏油庄冒菜带你领略舌尖在国外的影响
  10. Java中System.out.println()简单简介