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)
好的,这里是你执行的命令输出的中文解释:
-
ss -tlpn | grep sshd
和ss -tlpn | grep ssh
:- 这两个命令的输出都显示
sshd
(SSH守护进程)在端口22(*:22
)上处于监听状态,并且它的进程ID是926。
- 这两个命令的输出都显示
-
netstat -tlpn | grep sshd
:- 输出显示
sshd
也在端口22(0.0.0.0:22
)上监听,进程ID是926。
- 输出显示
-
lsof -i -P -n | grep sshd
:- 这个命令列出了活跃的连接,显示
sshd
在端口22上处于监听状态,并且有两个已建立的SSH连接:- 从
172.16.63.3:22
到8.139.112.39:16649
- 从
172.16.63.3:22
到8.139.112.145:43957
- 从
- 这个命令列出了活跃的连接,显示
从输出来看,SSH服务运行正常。