Securing a Linux server
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!
相关文章:
Securing a Linux server
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 l…...
DBeaver安装教程+连接TDengine数据库
为TDengine安装的DBeaver教程 安装 23.1.1 版本以上的DBeaver 因为官方文档说这个版本之上的DBeaver才支持TDengine内嵌前往DBeaver 官方文档进行版本下载滑到链接最下面点击进入 点击download,进入选择下载版本 等待下载成功即可双击自行安装 打开数据库连接TDen…...
postgreSQL window function高级用法
正常使用:相当于对每个row做一次子查询 SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;order by 区别window frame and partition 没有order by, window function是对整个partition起作用, part…...
【三维重建】Proc-GS:使用3DGS的程序性城市建筑生成
标题:《Proc-GS: Procedural Building Generation for City Assembly with 3D Gaussians》 项目:https://city-super.github.io/procgs/ 来源:香港中文大学;上海人工智能实验室 等 文章目录 摘要一、 程序代码定义 (Procedural Co…...
商业智能BI的未来,如何看待AI+BI这种模式?
昨天在和一位朋友线上聊天的时候,提了一个问题,你是如何看待AI(人工智能)BI(商业智能)这种模式和方向的,我大概来说一下我个人的看法。 以我在商业智能BI项目中接触到的行业和企业,…...
【计算机视觉】手势识别
手势识别是计算机视觉领域中的重要方向,通过对摄像机采集的手部相关的图像序列进行分析处理,进而识别其中的手势,手势被识别后用户就可以通过手势来控制设备或者与设备交互。完整的手势识别一般有手的检测和姿态估计、手部跟踪和手势识别等。…...
装饰器模式的C++实现示例
核心思想 装饰器设计模式是一种结构型设计模式,它允许动态地为对象添加额外的行为或职责,而无需修改其原始类。装饰器模式通过创建一个装饰器类来包装原始对象,并在保持原始对象接口一致性的前提下,扩展其功能。 装饰器模式的核…...
Python+DeepSeek:开启AI编程新次元——从自动化到智能创造的实战指南
文章核心价值 技术热点:结合全球最流行的编程语言与国产顶尖AI模型实用场景:覆盖代码开发/数据分析/办公自动化等高频需求流量密码:揭秘大模型在编程中的创造性应用目录结构 环境搭建:5分钟快速接入DeepSeek场景一:AI辅助代码开发(智能补全+调试)场景二:数据分析超级助…...
25.3.12.Linux内核如何和设备树协同工作的?
1.编写设备树 cd arch/riscv/boot/dts/ 再cd到厂商,例如下述内容。 2.编译设备树(dts->dtb)通过dtc命令来转换 3.解析设备树 例如上述内容,都是对设备树的解析。 这里重点说一下内核对设备树的处理吧,因为这个内容是设备树的重点了。 从源代码文件 dts 文件开始...
python中路径操作简介
一、./的基础含义 当前目录 ./表示当前工作目录(Current Working Directory, CWD),即Python脚本运行时所在的目录。例如: open(./data.txt, r) # 打开当前目录下的data.txt文件 作用:避免直接写文件名可能引发的路…...
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 的安装,相关安装教程可以参考【StarCoder 微调《个人编程助手: 训练你自己的编码助手》】中 5.1 之前的章节。 模型训练的相关知识可以参考 Torch的编程方…...
FreeSWITCH 之 chat
要把 FreeSWITCH 之 chat 完全研究清楚,似乎不容易 发送,路由,接收 跟哪些模块有关 等等 咱一边查资料,一边整理,不着急 先看看 Kamalio 怎么发 MESSAGE loadmodule "uac.so"route[uac_send_message] {…...
如何在Spring Boot中配置和使用MyBatis-Plus
在当今的Java开发中,Spring Boot已经成为了一个非常流行的框架,而MyBatis-Plus则是一个强大的ORM框架,为开发人员提供了更简便的数据库操作方式。很多开发者都在使用Spring Boot和MyBatis-Plus的组合来快速构建高效的应用。今天就来聊聊如何在…...
爱普生可编程晶振SG-8200CJ特性与应用
在高速发展的电子技术领域,时钟源作为电子系统的“心脏”,其性能直接影响设备的稳定性与可靠性。爱普生SG-8200CJ可编程晶振凭借其优秀的频率精度、低抖动性能及广泛的环境适应性,正成为众多领域的得力之选,为各类设备的高效运行与…...
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.如果容器停止运行(比如关机了&#…...
tslib
使用tslib来读取触摸屏的数据,可以得到原始数据,也可以在原始数据的基础上进行一些处理。比如有些触摸屏比较不稳定,跳动比较大,我们可以将跳动比较大的数据给删除掉 plugins里面的每个文件都会被编译成一个动态库,这些…...
MANUS怎么用
(1)分析方法论我过去说过一个分析模型:供给侧-消费侧。供给侧想做大,得靠生态集成。消费侧想坐大,得靠交互体验。(2)交互体验我先给大家讲一下计算机产业发展70来年,在交互上的变化。…...
Spring Cloud Alibaba 实战:Sentinel 保障微服务的高可用性与流量防护
1.1 Sentinel 作用 Sentinel 是阿里巴巴开源的一款 流量控制和熔断降级 框架,主要用于: 流量控制:限制 QPS,防止流量暴增导致系统崩溃熔断降级:当某个服务不可用时自动降级,避免故障扩散热点参数限流&…...
大数据技术在土地利用规划中的应用分析
大数据技术在土地利用规划中的应用分析 一、引言 土地利用规划是对一定区域内的土地开发、利用、整治和保护所作出的统筹安排与战略部署,对于实现土地资源的优化配置、保障社会经济的可持续发展具有关键意义。在当今数字化时代,大数据技术凭借其海量数据处理、高效信息挖掘等…...
MoonSharp 文档三
MoonSharp 文档一-CSDN博客 MoonSharp 文档二-CSDN博客 MoonSharp 文档四-CSDN博客 MoonSharp 文档五-CSDN博客 7.Proxy objects(代理对象) 如何封装你的实现,同时又为脚本提供一个有意义的对象模型 官方文档:MoonSharp 在实际…...
linux和windows之间的复制
第一步 sudo apt-get autoremove open-vm-tools第二步 sudo apt-get update第三步 sudo apt-get install open-vm-tools-desktop按y 第四步 重启虚拟机,终端下输入 rebootLinux下 按“ CtrlShiftC V ”复制粘贴 Windows下按“ Ctrl C V ”复制粘贴...
在资源有限中逆势突围:从抗战智谋到寒门高考的破局智慧
目录 引言 一、历史中的非对称作战:从李牧到八路军的智谋传承 李牧戍边:古代军事博弈中的资源重构 八路军的游击战:现代战争中的智慧延续 二、创业界的逆袭之道:小米与拼多多的资源重构 从MVP到杠杆解 社交裂变与资源错配 …...
Ubuntu 22.04 无法进入图形界面的解决方法
Ubuntu 22.04 无法进入图形界面,只能进入 tty,可能是由于图形界面相关的配置或驱动程序出现了问题。以下是一些常见的解决方法: 1. 检查图形界面服务状态 首先,检查图形界面服务(通常是 gdm 或 lightdm)的…...
Python中很常用的100个函数整理
Python 内置函数提供了强大的工具,涵盖数据处理、数学运算、迭代控制、类型转换等。本文总结了 100 个常用内置函数,并配备示例代码,提高编程效率。 1. abs() 取绝对值 print(abs(-10)) # 10 2. all() 判断所有元素是否为真 print(all([…...
javascript-es6 (六)
编程思想 面向过程 面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候再一个一个的依次 调用就可以了 就是按照我们分析好了的步骤,按照步骤解决问题 面向对象 面向对象是把事务分解成为一个个对象&…...
大模型微调技术基础(一)
文章目录 GPT与BERT的差异GPT(Decoder架构)优点缺点 BERT(Encoder架构)优点缺点 总结 LoRA低参数大模型与全参数小模型表现对比分析LoRA(Low-Rank Adaptation)技术详解1. LoRA 核心原理2. 应用场景3. 简单代…...
Spring AI 1.0.0 M6新特性MCP
Spring AI 1.0.0 M6新特性MCP 前言一、MCP是什么?(Model Context Protocol)二、它的发展历程三、核心架构四、MCP Java SDK的核心能力Java MCP实现遵循三层架构:MCP客户端MCP服务器总结MCP 的核心能力总结多种传输选项 搭建服务端…...
【时时三省】(C语言基础)赋值表达式和赋值语句和变量赋初值
山不在高,有仙则名。水不在深,有龙则灵。 ----CSDN 时时三省 赋值表达式和赋值语句 在C程序中,赋值语句是用得最多的语句。实际上,C语言的赋值语句属于表达式语句,由一个赋值表达式加一个分号组成。其他一些高级语言…...
Room数据库的使用
一、room的引用导入 1、在app的gradle中引入 plugins {//这个ksp 一定要对应相关的 kotlin 版本,不然会一直报错i的---id("com.google.devtools.ksp") version "1.9.0-1.0.13" apply false } 2、在model的gradle中引入 plugins {id("com.g…...
