修改ssh默认端口后,新的端口无法连接,而且监听的还是22端口

修改ssh默认端口后,新的端口无法连接,而且监听的还是22端口

问题描述:

我是本地装的Ubuntu,按照课程文档一步步装好的。防火墙也放行了

相关截图:


https://img1.sycdn.imooc.com//climg/6413e0e0096c395908400321.jpg

防火墙放行了

https://img1.sycdn.imooc.com//climg/6413e0e009f504a409620253.jpg

这是shhd_config 配置文件

https://img1.sycdn.imooc.com//climg/6413e0e009ba3c6e11130570.jpg

重启服务后还是监听的22端口

https://img1.sycdn.imooc.com//climg/6413e0e00983ccfb09760263.jpg

本地远程连接 连不上


请老师帮忙看看到底是什么问题!


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
Brian 2023-03-19 00:05:20
  1.  重启服务后——你确定你重启了吗?

  2. 配置Port需要检查一下配置文件中是否配置重复了!



+++++++++++分割线++++++++++++++++

在Ubuntu中修改SSH端口的步骤如下:


1.  以管理员权限登录到Ubuntu系统中。

2.  打开SSH配置文件: `sudo nano /etc/ssh/sshd_config`

3.  找到 `# Port 22` 这一行,将其修改为你想要的端口号,例如:`Port 2222`。

4.  保存并退出配置文件。

5.  重启SSH服务: `sudo service ssh restart`

    

现在,SSH服务已经被重新配置为使用新的端口号。接下来是配置密钥的步骤。


1.  在客户端生成一对密钥: `ssh-keygen`  

2.  将公钥传输到服务器: `ssh-copy-id username@server_ip_address -p port_number`

3.  连接服务器: `ssh username@server_ip_address -p port_number`

   

现在,你应该可以连接到服务器,并且无需输入密码即可完成认证。


  • 提问者 慕尼黑9393291 #1

    # This is the sshd server system-wide configuration file.  See

    # sshd_config(5) for more information.


    # This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games


    # The strategy used for options in the default sshd_config shipped with

    # OpenSSH is to specify options with their default value where

    # possible, but leave them commented.  Uncommented options override the

    # default value.


    Include /etc/ssh/sshd_config.d/*.conf


    # Port and ListenAddress options are not used when sshd is socket-activated,

    # which is now the default in Ubuntu.  See sshd_config(5) and

    # /usr/share/doc/openssh-server/README.Debian.gz for details.

    Port 10022

    #Port 22

    #AddressFamily any

    #ListenAddress 0.0.0.0

    #ListenAddress ::


    #HostKey /etc/ssh/ssh_host_rsa_key

    #HostKey /etc/ssh/ssh_host_ecdsa_key

    #HostKey /etc/ssh/ssh_host_ed25519_key


    # Ciphers and keying

    #RekeyLimit default none


    # Logging

    #SyslogFacility AUTH

    #LogLevel INFO


    # Authentication:


    #LoginGraceTime 2m

    PermitRootLogin yes

    #PermitRootLogin prohibit-password

    #StrictModes yes

    #MaxAuthTries 6

    #MaxSessions 10


    #PubkeyAuthentication yes


    # Expect .ssh/authorized_keys2 to be disregarded by default in future.

    #AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2


    #AuthorizedPrincipalsFile none


    #AuthorizedKeysCommand none

    #AuthorizedKeysCommandUser nobody


    # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts

    #HostbasedAuthentication no

    # Change to yes if you don't trust ~/.ssh/known_hosts for

    # HostbasedAuthentication

    #IgnoreUserKnownHosts no

    # Don't read the user's ~/.rhosts and ~/.shosts files

    #IgnoreRhosts yes


    # To disable tunneled clear text passwords, change to no here!

    #PasswordAuthentication yes

    #PermitEmptyPasswords no


    # Change to yes to enable challenge-response passwords (beware issues with

    # some PAM modules and threads)

    KbdInteractiveAuthentication no


    # Kerberos options

    #KerberosAuthentication no

    #KerberosOrLocalPasswd yes

    #KerberosTicketCleanup yes

    #KerberosGetAFSToken no


    # GSSAPI options

    #GSSAPIAuthentication no

    #GSSAPICleanupCredentials yes

    #GSSAPIStrictAcceptorCheck yes

    #GSSAPIKeyExchange no


    # Set this to 'yes' to enable PAM authentication, account processing,

    # and session processing. If this is enabled, PAM authentication will

    # be allowed through the KbdInteractiveAuthentication and

    # PasswordAuthentication.  Depending on your PAM configuration,

    # PAM authentication via KbdInteractiveAuthentication may bypass

    # the setting of "PermitRootLogin without-password".

    # If you just want the PAM account and session checks to run without

    # PAM authentication, then enable this but set PasswordAuthentication

    # and KbdInteractiveAuthentication to 'no'.

    UsePAM yes


    #AllowAgentForwarding yes

    #AllowTcpForwarding yes

    #GatewayPorts no

    X11Forwarding yes

    #X11DisplayOffset 10

    #X11UseLocalhost yes

    #PermitTTY yes

    PrintMotd no

    #PrintLastLog yes

    #TCPKeepAlive yes

    #PermitUserEnvironment no

    #Compression delayed

    #ClientAliveInterval 0

    #ClientAliveCountMax 3

    #UseDNS no

    #PidFile /run/sshd.pid

    #MaxStartups 10:30:100

    #PermitTunnel no

    #ChrootDirectory none

    #VersionAddendum none


    # no default banner path

    #Banner none


    # Allow client to pass locale environment variables

    AcceptEnv LANG LC_*


    # override default of no subsystems

    Subsystem       sftp    /usr/lib/openssh/sftp-server


    # Example of overriding settings on a per-user basis

    #Match User anoncvs

    #       X11Forwarding no

    #       AllowTcpForwarding no

    #       PermitTTY no

    #       ForceCommand cvs server


    这是我的sshd_config  没有重复配置端口

    https://img1.sycdn.imooc.com//climg/641832b509ff725711620579.jpg

    这是重启后依然监听的是22端口


    2023-03-20 18:18:35
  • Brian 回复 提问者 慕尼黑9393291 #2

    头一次遇到你这种情况啊,有没有在网上找一找方案啊?!!!

    2023-04-03 08:09:47
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师