linux 更改ssh端口

The default port on SSH is 22. But for security reasons, it’s a good idea to change SSH port in Linux. We’ll discuss why it’s necessary and how to make the change in a step by step manner.

SSH上的默认端口为22。但是出于安全原因,在Linux中更改SSH端口是一个好主意。 我们将逐步讨论为什么有必要,以及如何进行更改。

Requirements:

要求:

  • SSH ServerSSH服务器
  • Text Editor文本编辑器
  • Sudo Privileges须藤特权
  • 5 minutes of time5分钟的时间

This is a very quick and straightforward tutorial owing to the simplicity of the SSH server configuration file.

由于SSH服务器配置文件的简单性,这是一个非常快速和直接的教程。

在Linux中更改SSH端口的步骤 (Steps To Change SSH Port in Linux)

Let’s get right into the crux of the tutorial first and then move on to understand why we’d even need to change the port in the first place.

首先让我们直接进入本教程的重点,然后继续理解为什么我们首先需要更改端口。

1.选择正确的SSH端口 (1. Choose the Right SSH Port)

Ports are networking endpoints that decide where a data packet should be delivered. Based on the port number, the correct application on an Operating System receives the requested package.

端口是网络端点,用于确定应将数据包传递到何处。 根据端口号,操作系统上的正确应用程序将收到请求的程序包。

Out of those 65535 ports, the first 1023 ports are reserved for well-known services and 1024 to 49151 ports are registered ports. What’s left for us to play around with are the ephemeral ports which range from 49152 to 65535.

在这65535个端口中,前1023个端口保留用于知名服务,而1024至49151个端口是已注册的端口。 剩下的就是临时端口,范围从49152到65535。

To know the list of known ports: Wikipedia Page on Ports and How to Open ports on Linux

要了解已知端口的列表: 关于端口的维基百科页面以及如何在Linux上打开端口

2.查找SSH服务器在哪个端口上处于活动状态 (2. Find Which Port the SSH Server is Active on)

We’ll run the netstat utility to show us the port that SSH server is currently active on.

我们将运行netstat实用程序,向我们显示SSH服务器当前处于活动状态的端口。


root@ubuntu:~# netstat -tlpn
Netstat to Find Ssh Port
Netstat查找Ssh端口

As you can see in the Local Address column, the row across to 628/sshd says 0.0.0.0:22 which confirms that the listening port is 22 for our SSH server.

如您在“ 本地地址”列中所看到的,628 / sshd上的行表示0.0.0.0:22 ,这确认我们的SSH服务器的侦听端口为22。

3.在sshd_config文件中更改SSH端口 (3. Change SSH Port in the sshd_config File)

Now that we know we’re still listening to the default port for SSH connections, we can go ahead and change it.

现在我们知道我们仍在侦听SSH连接的默认端口,我们可以继续进行更改。

All we need to do is simply edit one line in the /etc/ssh/sshd_config file. Use any of your favorite terminal text editors to open the file with sudo privileges.

我们所需要做的只是在/ etc / ssh / sshd_config文件中编辑一行。 使用任何您喜欢的终端文本编辑器以sudo权限打开文件。


root@ubuntu:~# nano /etc/ssh/sshd_config

I haven’t used sudo since I’m already on a root account.

我没有使用sudo,因为我已经是root用户了。

Once the file is open, look for a line that says #Port 22. This is where the magic happens. Since this line is commented by default, it uses the default port that is 22. All we need to do is uncomment the line and change the port number.

打开文件后,寻找显示#Port 22的行 。 这就是魔术发生的地方。 由于默认情况下此行已注释,因此它使用的默认端口为22。我们要做的就是取消注释该行并更改端口号。

Editing SSH Port
编辑SSH端口

Now for demonstration purposes, I’ve selected 50000 as the port number for SSH. Once you’ve edited the port number as per your requirements, you can now save the file and move to the next step.

现在出于演示目的,我选择了50000作为SSH的端口号。 根据需要编辑端口号后,现在可以保存文件并转到下一步。

4.重新启动SSH服务并检查更新的端口 (4. Restart SSH Service and Check Updated Port)

Saved the file? Great, let’s restart SSH Server and run the same netstat command once again to check if the port was updated.

保存文件? 很好,让我们重新启动SSH Server并再次运行相同的netstat命令以检查端口是否已更新。

Run the below commands to get SSH server to restart and then run the netstat command again.

运行以下命令以使SSH服务器重新启动,然后再次运行netstat命令。


root@ubuntu:~# service sshd restart
root@ubuntu:~# netstat -tlpn
Ssh Updated Port
SSH更新的端口

You’re all set up now with a new SSH port that the SSH server is listening on.

现在,您已经全部设置好了SSH服务器正在侦听的新SSH端口。

为什么要更改Linux上的默认SSH端口? (Why Change Default SSH Port on Linux?)

If you read through the Wikipedia article or through the tutorial on opening ports in Linux you’ll know that if your server has port 22 open, it’s very obvious that your server is listening for SSH connections.

如果您通读Wikipedia文章或有关在Linux中打开端口的教程,您会知道,如果服务器打开了端口22,则很明显,您的服务器正在侦听SSH连接。

Hackers are always on a lookout for servers that broadcast their open ports. And if they can identify the service behind the port because the default port number is used, things become much easier for them.

黑客总是在寻找广播其开放端口的服务器。 而且由于使用默认端口号,如果他们可以识别端口后面的服务,则对他们而言,事情变得容易得多。

REMEMBER: Changing the port will not secure your server from attacks but it will make it less obvious for a hacker.

谨记:更改端口不会使服务器免受攻击,但对于黑客而言,它将变得不那么明显。

结论 (Conclusion)

This was it for our short tutorial on changing SSH ports. I hope you understood how to change ssh port in Linux and why you should consider changing the defaults whenever possible.

这就是我们有关更改SSH端口的简短教程。 我希望您了解如何在Linux中更改ssh端口以及为什么应该考虑尽可能更改默认值。

If you have any questions or get stuck at any point, feel free to comment below.

如果您有任何疑问或遇到困难,请在下面发表评论。

翻译自: https://www.journaldev.com/35523/how-to-change-ssh-port-in-linux

linux 更改ssh端口

linux 更改ssh端口_如何在Linux中更改SSH端口-简易指南相关推荐

  1. python如何更改entry属性_如何在Python3中更改Gtk3 Entry文本颜色?

    我在我的应用程序中有一个Gtk.Entry()列表,我想改变其中一些文本的颜色. 我尝试了以下方法: #!/usr/bin/python3 # Filename: mywindow.py from g ...

  2. windows ssh代理_如何在Windows上通过SSH设置代理?

    windows ssh代理 This tutorial teaches how to set up SSH proxy on Linux. 本教程讲解如何在Linux上设置SSH代理 . How to ...

  3. iptables 打开端口_如何在iptables中打开端口?

    iptables 打开端口 How to open a port, say 3389, in iptables to allow incoming traffics to it? 如何在iptable ...

  4. python绘图背景透明_如何在 Matplotlib 中更改绘图背景

    介绍Matplotlib是Python中使用最广泛的数据可视化库之一.无论是简单还是复杂的可视化项目,它都是大多数人的首选库.在本教程中,我们将研究如何在Matplotlib中更改绘图的背景.导入数据 ...

  5. python画图修改背景颜色_如何在 Matplotlib 中更改绘图背景的实现

    介绍 Matplotlib是Python中使用最广泛的数据可视化库之一.无论是简单还是复杂的可视化项目,它都是大多数人的首选库. 在本教程中,我们将研究如何在Matplotlib中更改绘图的背景. 导 ...

  6. chrome修改摄像头权限_如何在Chrome中更改网站的摄像头和麦克风权限

    chrome修改摄像头权限 Google Chrome lets you manage which individual sites can have access to your microphon ...

  7. mac app图标简单制作_如何在Mac中更改App图标

    mac app图标简单制作 Sometimes, apps icon change but we like the older icon. Thankfully, it's very easy to ...

  8. linux中更改用户密码_如何在Linux中更改用户密码

    linux中更改用户密码 In this tutorial, we will focus on how you can change a user's password in Linux. We wi ...

  9. linux重启网卡命令_如何在 Linux 中更改 MAC 地址 | Linux 中国

    在向你展示如何在 Linux 中更改 Mac 地址之前,让我们首先讨论为什么要更改它.-- Dimitrios Savvopoulos 在向你展示如何在 Linux 中更改 MAC 地址之前,让我们首 ...

最新文章

  1. mysql timestamp 更新_[mysql] timestamp自动更新和初始化
  2. 一文让你完全弄懂回归问题、激活函数、梯度下降和神经元模型实战《繁凡的深度学习笔记》第 2 章 回归问题与神经元模型(DL笔记整理系列)
  3. 支配vue框架模版语法之v-cloak
  4. 关于页面莫名空白的解决方式
  5. CAD批量提取数值lisp插件_一键批量提取CAD填充图案边界线
  6. linux之如何快速查看文件的大小
  7. ksu7对讲机调频软件_数字对讲机的群呼功能原理是什么?你了解多少?
  8. spring 启动加载数据_12个很棒的Spring数据教程来启动您的数据项目
  9. JavaScript 监听手机端的touch滑动事件(滑动手势)
  10. NLP实战-中文命名实体识别
  11. OpenShift 4 之Knative(2) - 第一个Serverless应用
  12. OC Gen X Mac(一键制作黑苹果OpenCore EFI文件)v最新版
  13. 有关libeva的使用说明 - 登录和登出操作
  14. 戴尔DELLEMC服务器重装CentOS 7系统
  15. 《全基因组测序WGS数据分析——1.DNA测序技术》
  16. 通过追女孩时的常见对话来看你会不会聊天
  17. stata如何快速导出表格
  18. 宽依赖和窄依赖_Spark --【宽依赖和窄依赖】
  19. 更简单获取到Bean对象(1)
  20. numpy生成随机整数

热门文章

  1. CodeForces - 556C Case of Matryoshkas
  2. Shut Down(or Closing) Your Windows and Open The Unix
  3. [转载] python实现基本算法之插入排序(Insertion Sort)
  4. [转载] PYTHON 字符串转换为二进制字符串,二进制字符串转换为字符串
  5. WEB 端批量移动设备管理控制工具 STF 的环境搭建和运行
  6. git push --set-upstream
  7. springmvc国际化 基于请求的国际化配置
  8. Oracle:lsnrctl start Timeout or Adapter error
  9. javascript 经常会用到的东西
  10. 中国移动创新系列丛书《OPhone应用开发权威指南》读者交流活动圆满结束