root@imooc是服务器端的centos,为什么可以修改本地ssh向外请求的端口?

来源:2-9 SSH密钥方式远程连接Linux

慕侠3297407

2022-10-10 21:26:38

在服务端的centos修改了端口后,ctrl+d断开连接,在本地cmd用ssh连接centos失败(已关闭防火墙)。

[root@iZbp15upsrdbnylnrfbgsvZ ~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
[root@iZbp15upsrdbnylnrfbgsvZ ~]# ^C
[root@iZbp15upsrdbnylnrfbgsvZ ~]# logout
Connection to 121.41.79.189 closed.

C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>
C:\WINDOWS\system32>
C:\WINDOWS\system32>
C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>
C:\WINDOWS\system32>
C:\WINDOWS\system32>firewall-cmd --list-ports
'firewall-cmd' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\WINDOWS\system32>firewall --list-ports
'firewall' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\WINDOWS\system32>semanage port -l |grep ssh
'semanage' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\WINDOWS\system32>ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

C:\WINDOWS\system32>netstat -anlp | grep sshd
'grep' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\WINDOWS\system32>ssh root@121.41.79.189
ssh: connect to host 121.41.79.189 port 22: Connection refused

C:\WINDOWS\system32>ssh -p 22 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 22: Connection refused

C:\WINDOWS\system32>ssh -p 22 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 22: Connection refused

C:\WINDOWS\system32>ssh root@121.41.79.189
ssh: connect to host 121.41.79.189 port 22: Connection refused

C:\WINDOWS\system32>ssh -V
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5

C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>
C:\WINDOWS\system32>
C:\WINDOWS\system32>ssh -p 10022 root@121.41.79.189
ssh: connect to host 121.41.79.189 port 10022: Connection timed out

C:\WINDOWS\system32>ssh root@121.41.79.189
ssh: connect to host 121.41.79.189 port 22: Connection refused


写回答

1回答

Brian

2022-10-11

root@imooc

——老师是设置了imooc的配置文件的,如下:

~/.ssh/config


Host imooc

  Port 22

  HostName xxx.xxx.xxx.xxxx

  User root

  IdentityFile ~/.ssh/servers/imooc

  IdentitiesOnly yes


这样可以免密登录。


从你上面的截图与错误来看,有两个错误:1. 没有使用windows上的终端工具。


PS: windows上推荐终端工具


xshell

finalshell

git shell

Termius


2. 购买的云主机或者虚拟主机,不清楚IP地址与SSH连接的方式。


可以Q群私信一下我

0

大前端2022版

1个业务场景打通全端、全栈、全流程,实现全局思维与综合技术能力全面突破;对标阿里P6,8个月成为前端高级人才

2840 学习 · 691 问题

查看课程