修改Linux服务器SSH默认端口

蔚落 2023-07-04 06:27 77阅读 0赞

linux系统的默认端口配置是22,在配置文件/etc/ssh/sshd_config中

  1. # $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
  2. # This is the sshd server system-wide configuration file. See
  3. # sshd_config(5) for more information.
  4. # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
  5. # The strategy used for options in the default sshd_config shipped with
  6. # OpenSSH is to specify options with their default value where
  7. # possible, but leave them commented. Uncommented options change a
  8. # default value.
  9. #Port 22
  10. #AddressFamily any
  11. #ListenAddress 0.0.0.0
  12. #ListenAddress ::
  13. # Disable legacy (protocol version 1) support in the server for new
  14. # installations. In future the default will change to require explicit
  15. # activation of protocol 1
  16. Protocol 2
  17. # HostKey for protocol version 1
  18. #HostKey /etc/ssh/ssh_host_key
  19. # HostKeys for protocol version 2
  20. #HostKey /etc/ssh/ssh_host_rsa_key
  21. #HostKey /etc/ssh/ssh_host_dsa_key
  22. # Lifetime and size of ephemeral version 1 server key
  23. #KeyRegenerationInterval 1h
  24. #ServerKeyBits 1024
  25. # Logging
  26. # obsoletes QuietMode and FascistLogging
  27. #SyslogFacility AUTH
  28. SyslogFacility AUTHPRIV
  29. #LogLevel INFO
  30. # Authentication:
  31. #LoginGraceTime 2m
  32. PermitRootLogin yes
  33. #StrictModes yes
  34. #MaxAuthTries 6
  35. #MaxSessions 10
  36. #RSAAuthentication yes
  37. #PubkeyAuthentication yes
  38. #AuthorizedKeysFile .ssh/authorized_keys
  39. #AuthorizedKeysCommand none
  40. #AuthorizedKeysCommandRunAs nobody
  41. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
  42. #RhostsRSAAuthentication no
  43. # similar for protocol version 2
  44. #HostbasedAuthentication no
  45. # Change to yes if you don't trust ~/.ssh/known_hosts for
  46. # RhostsRSAAuthentication and HostbasedAuthentication
  47. #IgnoreUserKnownHosts no
  48. # Don't read the user's ~/.rhosts and ~/.shosts files
  49. #IgnoreRhosts yes
  50. # To disable tunneled clear text passwords, change to no here!
  51. #PasswordAuthentication yes
  52. #PermitEmptyPasswords no
  53. PasswordAuthentication yes
  54. # Change to no to disable s/key passwords
  55. #ChallengeResponseAuthentication yes
  56. ChallengeResponseAuthentication no
  57. # Kerberos options
  58. #KerberosAuthentication no
  59. #KerberosOrLocalPasswd yes
  60. #KerberosTicketCleanup yes
  61. #KerberosGetAFSToken no
  62. #KerberosUseKuserok yes
  63. # GSSAPI options
  64. #GSSAPIAuthentication no
  65. GSSAPIAuthentication yes
  66. #GSSAPICleanupCredentials yes
  67. GSSAPICleanupCredentials yes
  68. #GSSAPIStrictAcceptorCheck yes
  69. #GSSAPIKeyExchange no
  70. # Set this to 'yes' to enable PAM authentication, account processing,
  71. # and session processing. If this is enabled, PAM authentication will
  72. # be allowed through the ChallengeResponseAuthentication and
  73. # PasswordAuthentication. Depending on your PAM configuration,
  74. # PAM authentication via ChallengeResponseAuthentication may bypass
  75. # the setting of "PermitRootLogin without-password".
  76. # If you just want the PAM account and session checks to run without
  77. # PAM authentication, then enable this but set PasswordAuthentication
  78. # and ChallengeResponseAuthentication to 'no'.
  79. #UsePAM no
  80. UsePAM yes
  81. # Accept locale-related environment variables
  82. AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  83. AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  84. AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
  85. AcceptEnv XMODIFIERS
  86. #AllowAgentForwarding yes
  87. #AllowTcpForwarding yes
  88. #GatewayPorts no
  89. #X11Forwarding no
  90. X11Forwarding yes
  91. #X11DisplayOffset 10
  92. #X11UseLocalhost yes
  93. #PrintMotd yes
  94. #PrintLastLog yes
  95. #TCPKeepAlive yes
  96. #UseLogin no
  97. #UsePrivilegeSeparation yes
  98. #PermitUserEnvironment no
  99. #Compression delayed
  100. #ClientAliveInterval 0
  101. #ClientAliveCountMax 3
  102. #ShowPatchLevel no
  103. #UseDNS yes
  104. #PidFile /var/run/sshd.pid
  105. #MaxStartups 10:30:100
  106. #PermitTunnel no
  107. #ChrootDirectory none
  108. # no default banner path
  109. #Banner none
  110. # override default of no subsystems
  111. Subsystem sftp /usr/libexec/openssh/sftp-server
  112. # Example of overriding settings on a per-user basis
  113. #Match User anoncvs
  114. # X11Forwarding no
  115. # AllowTcpForwarding no
  116. # ForceCommand cvs server
  117. UseDNS no

直接修改配置,将Port配置打开,并将端口号改为自需的即可,然后重启ssh服务即可

[root@instance-38r7isl1 /]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@instance-38r7isl1 /]#

发表评论

表情:
评论列表 (有 0 条评论,77人围观)

还没有评论,来说两句吧...

相关阅读