要查询 SSH 服务的端口号(使用 ss 命令:sudo ss -tlpn | grep sshd)Ubuntu

root@ordercenter:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

好的,要查询 SSH 服务的端口号,你可以尝试以下方法。 假设你有服务器的 Shell 访问权限 (例如通过 SSH 登录):

1. 使用 ss 命令 (推荐):

sudo ss -tlpn | grep sshd

这个命令会列出所有 TCP 监听端口 (-t),以数字形式显示地址和端口 (-n),显示进程信息 (-p),然后使用 grep 过滤出包含 “sshd” 的行。 sshd 通常是 SSH 守护进程的名称。

如果 sshd 不是正确的进程名称,可以尝试以下命令 (搜索任何包含 “ssh” 的进程):

sudo ss -tlpn | grep ssh

2. 使用 netstat 命令:

sudo netstat -tlpn | grep sshd

这个命令与 ss 命令类似,但使用 netstat 工具。

3. 使用 lsof 命令:

sudo lsof -i -P -n | grep sshd

sudo lsof -i -P -n | grep ssh

root@ordercenter:~# sudo ss -tlpn | grep sshd
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=926,fd=3))
root@ordercenter:~# sudo ss -tlpn | grep ssh
LISTEN     0      128          *:22                       *:*                   users:(("sshd",pid=926,fd=3))
root@ordercenter:~# sudo netstat -tlpn | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      926/sshd        
root@ordercenter:~# sudo lsof -i -P -n | grep sshd
sshd        926    root    3u  IPv4     14285      0t0  TCP *:22 (LISTEN)
sshd      15707    root    3u  IPv4 593285203      0t0  TCP 172.16.63.3:22->8.139.112.39:16649 (ESTABLISHED)
sshd      16307    root    3u  IPv4 593305868      0t0  TCP 172.16.63.3:22->8.139.112.145:43957 (ESTABLISHED)
root@ordercenter:~# sudo lsof -i -P -n | grep ssh
sshd        926    root    3u  IPv4     14285      0t0  TCP *:22 (LISTEN)
sshd      15707    root    3u  IPv4 593285203      0t0  TCP 172.16.63.3:22->8.139.112.39:16649 (ESTABLISHED)
sshd      16356    root    3u  IPv4 593307396      0t0  TCP 172.16.63.3:22->8.139.112.48:27611 (ESTABLISHED)

好的,这里是你执行的命令输出的中文解释:

  1. ss -tlpn | grep sshdss -tlpn | grep ssh

    • 这两个命令的输出都显示 sshd(SSH守护进程)在端口22(*:22)上处于监听状态,并且它的进程ID是926。
  2. netstat -tlpn | grep sshd

    • 输出显示 sshd 也在端口22(0.0.0.0:22)上监听,进程ID是926。
  3. lsof -i -P -n | grep sshd

    • 这个命令列出了活跃的连接,显示 sshd 在端口22上处于监听状态,并且有两个已建立的SSH连接:
      • 172.16.63.3:228.139.112.39:16649
      • 172.16.63.3:228.139.112.145:43957

从输出来看,SSH服务运行正常。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值