Securing a Linux server

news2025/3/12 15:30:46

Is your Linux server safe from hackers? Can they get hacked? Freak out about getting your server compromised and getting your data leaked? Take a look at some of the tips you can take to secure and protect your Linux server.
 

1. SSH security

SSH is like a path to connect you to your Linux server. Of course, you will have to secure the passage. Hackers can access your server the same way you access your server.
 

SSH Port

Everyone knows that SSH uses the default port 22 to connect to your server. To avoid letting people know that your SSH is open to connection, change the port so hackers that scan port 22 will not know that your server's SSH is active. The best practice is to change your SSH ports to a different port between 10000 and 32767.
 

To change your SSH ports, edit SSH config

vi /etc/ssh/sshd_config

Find this line

#Port 22

change port value

Port <Random Ports>

Don't forget to restart your ssh server to apply the settings.

systemctl restart sshd

2. SSH Keys

Password can easily get bruteforced, trying keying in your Password in How Secure Is My Password? | Password Strength Checker | Security.org and find out how long does it take for a hacker to crack your password. Scary isn't it?

Now, how about cracking a 4096 bits SSH key? Good luck with that, Mr. Hackers.
 

To set up an SSH key, use the code to generate a rsa 4096 bit key pair

ssh-keygen -t rsa -b 4096


On Windows machine (cmd), this will be

C:\Users\evoxt>ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\evoxt/.ssh/id_rsa):
Created directory 'C:\Users\evoxt/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\evoxt/.ssh/id_rsa.
Your public key has been saved in C:\Users\evoxt/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RSM1LY13KzUzgSziCz1gLKfTSLs3YtgKBtHdQGdX2SQ evoxt@DESKTOP-DU15VE5
The key's randomart image is:
+---[RSA 4096]----+
| . oo+o ooEO.... |
|. . +o*..o=+B * |
| . . O + ..+ o = |
|. = o +. . . |
|. o o .So . |
|... = o . |
|.. o o . |
| . |
| |
+----[SHA256]-----+
C:\Users\evoxt>

Then, you will have to manually copy the ssh public key to your server ( ~/.ssh/authorized_keys )
 

The formatting will be

ssh-rsa <generated_public_key>

Example:

[root@evoxt .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDPsDZ5LPRriU4wDjZVzSVdqVzWNlaon2WdOm9v1AsAp+9R0u+dyy0YiXcxhF9rjK4bnLc840pw2AiCiQIEwfXS03jVA3b1q1yqCqyiO3WVf+SGuL9m+GXq9hNsRCHznGhhsoi9VbbED5ECMFYoU6SeVucXntEtfR32C8Hnb1eBCICU5GXrZpIqEgqZrnDEVKzMUS/T4HjGGnT4puQDEg++e33HE3z0vr7PXbDW2RR1kIsRdNS0/BfdlPCXf1lA8aAkKWq49rGO5T5PT4+bCDh7aVCS5ouTfL0qJNpyijBudRvHy4DUuzdqNJLEcR4DYZRSXEQsYc+oK+5mjvcGFNQXbx8bQNYyGtERBfAVuWSTsk8oVwRwbo9YIzkMYKyf1GwJvoggKHCsx+s0gHcAo0LSU7BFXVJMS5NY6Zvw6Cv+z/UUokVkTZ/CkTiTJHhVJjzLkeqmFPWbxEWSWED5RUuCnWTmHcV6Fkc3sbUAwp+qRdQgVcGPYigpa8/dsyLWFTbdK1fe5UUeY5C3UbBqr6bItn42tJCNPcu6YpxtfdxDtq/IDWGRsZltM15FEFCrvBGX8JD1z1H3S+j3GjFJtA1iW1cODOV5l+s0sUS64OnY+o0hpsqs2Mie4Xy/zzKg5C071wHIORML1tZq40ZETmwCUXlwmv4shay5cJJm/Ss3qQ==

[root@evoxt ~]#


On a Linux machine, this will be

[root@evoxt ~]# ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:eIS1I1I0YXgvjR9igqAipDp0j3D+CYpyqjuJQ02ugZ8 root@evoxt
The key's randomart image is:
+---[RSA 4096]----+
| o*.. |
|.. .o.+ . |
|+. ...o++ |
|=o.+..=++. |
|* O oo.+S. |
|+o * . .. |
|+++.o . |
|BoE o |
|** |
+----[SHA256]-----+
[root@evoxt ~]#

Then, you can use ssh-copy-id command to install the ssh public key.

ssh-copy-id user@your_server_ip

[root@evoxt ~]# ssh-copy-id root@xx.xx.xx.xx
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'xx.xx.xx.xx (xx.xx.xx.xx)' can't be established.
ECDSA key fingerprint is SHA256:umf+E/a0OQe8eRmPdYyCM5kE+ZG/FCC2MEEn2G81dGA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@xx.xx.xx.xx's password:
 

Number of key(s) added: 1
 

Now try logging into the machine, with "ssh 'root@xx.xx.xx.xx'"
and check to make sure that only the key(s) you wanted were added.
 

[root@evoxt ~]#


 

SSH from Specific IP

To allow specific IP to access your server through SSH, configure the firewall only to allow a single IP address to go through the firewall to your SSH port.
 

Make sure you have a static IP before doing this. Else you can get locked out of your server.
 

Disable Password Authentication

Once SSH key authentication has been set up, disable password authentication.

sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config

Then restart SSH service

systemctl restart sshd

3. Automatic updates

Zero-day exploits are attacks that you can't react to. The best thing next is to protect yourself from N-day attacks once the zero-day exploit has been discovered. To protect yourself from N-day attacks, enable automatic updates. Keep in mind that automatic updates can potentially mess things up. To reduce the chances, enable automatic security only.
 

To enable automatic security updates, use this guide.
 

4. Default password

Change your server's default password. Most default passwords are stored in databases and your email inbox. Change them!
 

To change your server's password,

passwd <user>

[root@TEST ~]# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@TEST ~]#

5. Private Networks and VPNs

Set up a server and connect to your servers through a private network. Private network uses private IP to communicate with each other isolating your servers from the public without any exposure to the public.
 

To set up a private network or a VPN. Take a look at Pritunl. They offer many advanced features such as organization management to separate between Private networks, and it also comes with GUI to easily configure the server.
 

6. Firewall

Set up a firewall to block unnecessary open ports.
 

Most Linux distributions includes Iptables by default.
 

To control your Iptables:

  • CentOS/ Fedora uses FirewallD
  • Ubuntu/ Debian uses UFW.

To take a look for running programs that are currently using specific ports, use netstat

netstat -tulpn

Also, block ICMP Ping if not required.

With ICMP blocked, hackers have a harder time knowing your server is currently up and running.
 

7. Users

Root access is scary! With root access, the hacker can do almost anything to your servers.
 

Because root access is so powerful, hackers tend to try to crack and brute force root accounts. Hackers will usually stay away from other user accounts if you disable root user access due to the lack of permissions.
 

The most common practice is to block root access through SSH.
 

To disable root access through SSH

vi /etc/ssh/sshd_config

Change PermitRootLogin from yes to no and remove the # comment if there is any
 

#PermitRootLogin yes

to

PermitRootLogin no

Or use this simple command to disable root login.

sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

Don't forget to restart your ssh service to apply the settings.

systemctl restart sshd

Note: Please make sure you have other users account created with sufficient permission to avoid getting locked out of your server.
 

8. Backup

This is not quite related to server security. However, I believe this is super important to be included.
 

It is crucial to have a server backup just in case something goes wrong.
 

When a server is hacked, backup files will be your savior.
 

Store your backup offsite, so the hacker cannot modify or alter your backup files.
 

Luckily for you, all servers under Evoxt will be backup weekly on an offsite server. If you are not using Evoxt yet, consider upgrading!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2313817.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

DBeaver安装教程+连接TDengine数据库

为TDengine安装的DBeaver教程 安装 23.1.1 版本以上的DBeaver 因为官方文档说这个版本之上的DBeaver才支持TDengine内嵌前往DBeaver 官方文档进行版本下载滑到链接最下面点击进入 点击download&#xff0c;进入选择下载版本 等待下载成功即可双击自行安装 打开数据库连接TDen…

【三维重建】Proc-GS:使用3DGS的程序性城市建筑生成

标题&#xff1a;《Proc-GS: Procedural Building Generation for City Assembly with 3D Gaussians》 项目&#xff1a;https://city-super.github.io/procgs/ 来源&#xff1a;香港中文大学&#xff1b;上海人工智能实验室 等 文章目录 摘要一、 程序代码定义 (Procedural Co…

商业智能BI的未来,如何看待AI+BI这种模式?

昨天在和一位朋友线上聊天的时候&#xff0c;提了一个问题&#xff0c;你是如何看待AI&#xff08;人工智能&#xff09;BI&#xff08;商业智能&#xff09;这种模式和方向的&#xff0c;我大概来说一下我个人的看法。 以我在商业智能BI项目中接触到的行业和企业&#xff0c;…

25.3.12.Linux内核如何和设备树协同工作的?

1.编写设备树 cd arch/riscv/boot/dts/ 再cd到厂商,例如下述内容。 2.编译设备树(dts->dtb)通过dtc命令来转换 3.解析设备树 例如上述内容,都是对设备树的解析。 这里重点说一下内核对设备树的处理吧,因为这个内容是设备树的重点了。 从源代码文件 dts 文件开始

Flutter 基础组件 Text 详解

目录 1. 引言 2. 基本使用 3. 自定义样式 4. 文本对齐与溢出控制 5. 外边距 5.1 使用 Container 包裹 5.2 使用 Padding 组件 5.3 在 Row/Column 中使用 5.4 动态边距调整 5.5 关键区别说明 5.6 设置 margin 无效 6. 结论 相关推荐 1. 引言 Text 组件是 Flutter 中…

Torch 模型 model => .onnx => .trt 及利用 TensorTR 在 C++ 下的模型部署教程

一、模型训练环境搭建和模型训练 模型训练环境搭建主要牵扯 Nvidia driver、Cuda、Cudnn、Anaconda、Torch 的安装&#xff0c;相关安装教程可以参考【StarCoder 微调《个人编程助手: 训练你自己的编码助手》】中 5.1 之前的章节。 模型训练的相关知识可以参考 Torch的编程方…

爱普生可编程晶振SG-8200CJ特性与应用

在高速发展的电子技术领域&#xff0c;时钟源作为电子系统的“心脏”&#xff0c;其性能直接影响设备的稳定性与可靠性。爱普生SG-8200CJ可编程晶振凭借其优秀的频率精度、低抖动性能及广泛的环境适应性&#xff0c;正成为众多领域的得力之选&#xff0c;为各类设备的高效运行与…

ubuntu中用docker下载opengauss

1.安装docker sudo apt install docker.io2.拉取opengauss镜像 sudo docker pull enmotech/opengauss3.创建容器 sudo docker run --name opengauss --privilegedtrue -d -e GS_PASSWORDEnmo123 enmotech/opengauss:latest3.5.如果容器停止运行&#xff08;比如关机了&#…

tslib

使用tslib来读取触摸屏的数据&#xff0c;可以得到原始数据&#xff0c;也可以在原始数据的基础上进行一些处理。比如有些触摸屏比较不稳定&#xff0c;跳动比较大&#xff0c;我们可以将跳动比较大的数据给删除掉 plugins里面的每个文件都会被编译成一个动态库&#xff0c;这些…

MoonSharp 文档三

MoonSharp 文档一-CSDN博客 MoonSharp 文档二-CSDN博客 MoonSharp 文档四-CSDN博客 MoonSharp 文档五-CSDN博客 7.Proxy objects&#xff08;代理对象&#xff09; 如何封装你的实现&#xff0c;同时又为脚本提供一个有意义的对象模型 官方文档&#xff1a;MoonSharp 在实际…

linux和windows之间的复制

第一步 sudo apt-get autoremove open-vm-tools第二步 sudo apt-get update第三步 sudo apt-get install open-vm-tools-desktop按y 第四步 重启虚拟机&#xff0c;终端下输入 rebootLinux下 按“ CtrlShiftC V ”复制粘贴 Windows下按“ Ctrl C V ”复制粘贴

在资源有限中逆势突围:从抗战智谋到寒门高考的破局智慧

目录 引言 一、历史中的非对称作战&#xff1a;从李牧到八路军的智谋传承 李牧戍边&#xff1a;古代军事博弈中的资源重构 八路军的游击战&#xff1a;现代战争中的智慧延续 二、创业界的逆袭之道&#xff1a;小米与拼多多的资源重构 从MVP到杠杆解 社交裂变与资源错配 …

javascript-es6 (六)

编程思想 面向过程 面向过程就是分析出解决问题所需要的步骤&#xff0c;然后用函数把这些步骤一步一步实现&#xff0c;使用的时候再一个一个的依次 调用就可以了 就是按照我们分析好了的步骤&#xff0c;按照步骤解决问题 面向对象 面向对象是把事务分解成为一个个对象&…

Spring AI 1.0.0 M6新特性MCP

Spring AI 1.0.0 M6新特性MCP 前言一、MCP是什么&#xff1f;&#xff08;Model Context Protocol&#xff09;二、它的发展历程三、核心架构四、MCP Java SDK的核心能力Java MCP实现遵循三层架构&#xff1a;MCP客户端MCP服务器总结MCP 的核心能力总结多种传输选项 搭建服务端…

【性能测试入门_01性能测试jmeter基础实操场景详解】

一、应用项目如何部署在服务器上 可以将项目进行打jar包 双击install&#xff0c;控制台就会打印打包的过程 最终打的包&#xff0c;会存放在打印的那个路径下 这个jar包&#xff0c;就是开发人员开发好&#xff0c;直接可以部署的 可以通过命令&#xff0c;在终端直接启动这…

跨越时空的对话:图灵与GPT-4聊AI的前世今生

&#xff08;背景&#xff1a;虚拟咖啡厅&#xff0c;图灵身着1950年代西装&#xff0c;端着一杯热茶&#xff0c;GPT-4以全息投影形态坐在对面&#xff09; 图灵&#xff08;喝了口茶&#xff09;&#xff1a;“听说你能写诗&#xff1f;我当年在布莱切利园破解Enigma时&…

如何通过 Seatunnel 实现 MySQL 到 OceanBase的数据迁移同步

1. 准备传输工具 本方案采用 Apache Seatunnel&#xff08;简称seatunnel&#xff09;进行MySQL 到 OceanBase 的数据迁移和同步&#xff0c;出于对方案轻量性的考量&#xff0c;我们采用其内置的Zeta引擎来实现&#xff0c;包括全量同步、离线增量同步&#xff0c;以及CDC方案…

软件设计模式之简单工厂模式

目录 一.类图&#xff08;手机生产&#xff09; 二.代码实现 Iphone类&#xff1a; Vivo类&#xff1a; Mobile类&#xff1a; MobileFactory类&#xff1a; Client类&#xff1a; 一.类图&#xff08;手机生产&#xff09; 补充&#xff1a;MobileFactory也可以直接指向…

LiveGBS流媒体平台GB/T28181常见问题-视频流安全控制HTTP接口鉴权勾选流地址鉴权后401Unauthorized如何播放调用接口流地址校验

LiveGBS流媒体平台GB/T28181常见问题频流安全控制HTTP接口鉴权勾选流地址鉴权后401Unauthorized如何播放调用接口流地址校验&#xff1f; 1、安全控制1.1、HTTP接口鉴权1.2、流地址鉴权 2、401 Unauthorized2.1、携带token调用接口2.1.1、获取鉴权token2.1.2、调用其它接口2.1.…

Java 大视界 -- 区块链赋能 Java 大数据:数据可信与价值流转(84)

&#x1f496;亲爱的朋友们&#xff0c;热烈欢迎来到 青云交的博客&#xff01;能与诸位在此相逢&#xff0c;我倍感荣幸。在这飞速更迭的时代&#xff0c;我们都渴望一方心灵净土&#xff0c;而 我的博客 正是这样温暖的所在。这里为你呈上趣味与实用兼具的知识&#xff0c;也…