百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

运维笔记:购买vps服务器后,在Linux最初需要做的几件事

nanshan 2024-12-22 19:56 51 浏览 0 评论


本人系统为CentOS 8

可通过 命令 cat /etc/redhat-release 查看自己的系统版本

[root@EasygoingEssential-VM /]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

命令 uname -a 可以查看内核版本

[root@EasygoingEssential-VM /]# uname -a
Linux EasygoingEssential-VM 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


1:更改root原始密码

命令输入 passwd 用户名(不输用户名,表示当前用户),输入两遍密码

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

2: 安装bash-completion Tab补齐

按Tab建没法补齐命令,所以需要自己安装bash-completion

命令输入 yum -y install bash-completion

[root@EasygoingEssential-VM /]# yum -y install bash-completion

重新登录生效

3: 安装第三方源epel-release,和国内yum源

自己安装的是阿里yum源

1),备份原有源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2),下载阿里源

本人系统版本为CentOS-8,所以下载

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

如果其他版本如CentOS-7,则

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

显示如下:

[root@EasygoingEssential-VM ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
--2021-06-15 09:17:20-- https://mirrors.aliyun.com/repo/Centos-8.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 47.246.22.232, 47.246.22.233, 47.246.22.234, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|47.246.22.232|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2595 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
/etc/yum.repos.d/CentO 100%[===========================>] 2.53K --.-KB/s in 0s
2021-06-15 09:17:22 (15.1 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2595/2595]

最后清除系统所有的yum缓存

yum clean all 

生成yum缓存

yum makecache 

安装完成!!!!!1

如果没有wget 命令,会提示 -bash: wget: command not found

同样先安装 yum -y install wget即可;

3:安装epel-release

命令:

yum install -y epel-release 

显示如下:

[root@EasygoingEssential-VM ~]# yum install -y epel-release
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - Base - mirrors.aliyun.com 897 kB/s | 2.6 MB 00:02
CentOS-8 - Extras - mirrors.aliyun.com 3.0 kB/s | 9.6 kB 00:03
....
....
Installed:
epel-release-8-8.el8.noarch
Complete!
[root@EasygoingEssential-VM ~]#

安装成功!!!

yum repolist enabled 可查看可用的yum源

yum repolist all 显示所有yum源

显示如下:

[root@EasygoingEssential-VM ~]# yum repolist enabled
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:00:18 ago on Tue 15 Jun 2021 09:36:37 AM EDT.
repo id repo name status
AppStream CentOS-8 - AppStream 5,289
base CentOS-8 - Base - mirrors.aliyun.com 1,744
*epel Extra Packages for Enterprise Linux 8 - x86_64 7,437
*epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64 0
extras CentOS-8 - Extras - mirrors.aliyun.com 34

4:更改ssh端口或者禁用root远程登陆

禁用root前,需要创建一个普通用户及远程登陆密码

useradd slan 创建一个为slan的用户

passwd slan 设置用户slan的密码

显示:

[root@EasygoingEssential-VM ~]# useradd slan
[root@EasygoingEssential-VM ~]# passwd slan
Changing password for user test.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@EasygoingEssential-VM ~]#

然后编辑ssh配置文件

vi /etc/ssh/sshd_config

Port 22 改为 Port 9527(1到65535之间,且没有被占用),并删掉前面的# 注释符

PermitRootLogin yes 改为 PermitRootLogin no 禁用root远程登陆

大概配置文件如下:

Port 9527
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
```
```xml
#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

完成,保存重启ssh服务生效。

注: 更改端口一定要关闭防火墙,否则无法用新端口连接ssh.或者自己设置防火墙放行

systemctl stop firewalld.service 关闭防火墙

systemctl disable firewalld.service关闭开机启动

[root@EasygoingEssential-VM ~]# systemctl stop firewalld.service
[root@EasygoingEssential-VM ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.

以后ssh登录用创建的slan普通用户登录,登录后可用`su - `切换root用户。

5:更改终端命令行颜色(可选)

更改终端命令行颜色,为了更加直观方便以后观看及查看命令。

更改

vi /etc/profile 此文件对所有用户有效,如果只对当前用户有效,则vi .bashrc

在最后面加上

PS1='[\[\e[32m\]\u\[\e[0m\]\[\e[35m\]@\[\e[0m\]\[\e[33m\]\h\[\e[0m\]\[\e[36m\] \W\[\e[0m\]]\$ '

最后

source /etc/profile 更新文件,可以看到命令行颜色已变化。

相关推荐

Let’s Encrypt免费搭建HTTPS网站

HTTPS(全称:HyperTextTransferProtocoloverSecureSocketLayer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入...

使用Nginx配置TCP负载均衡(nginx tcp负载)

假设Kubernetes集群已经配置好,我们将基于CentOS为Nginx创建一个虚拟机。以下是实验种设置的详细信息:Nginx(CenOS8Minimal)-192.168.1.50Kube...

Nginx负载均衡及支持HTTPS与申请免费SSL证书

背景有两台minio文件服务器已做好集群配置,一台是192.168.56.41:9000;另一台是192.168.56.42:9000。应用程序通过Nginx负载均衡调用这两台minio服务,减轻单点...

HTTPS配置实战(https配置文件)

原因现在网站使用HTTPS是规范操作之一,前些日子买了腾讯云服务,同时申请了域名http://www.asap2me.top/,目前该域名只支持HTTP,想升级为HTTPS。关于HTTPS的链接过程大...

只有IP地址没有域名实现HTTPS访问方法

一般来说,要实现HTTPS,得有个注册好的域名才行。但有时候呢,咱只有服务器的IP地址,没注册域名,这种特殊情况下,也能照样实现HTTPS安全访问,按下面这些步骤来就行:第一步,先确认公网...

超详解:HTTPS及配置Django+HTTPS开发环境

众所周知HTTP协议是以TCP协议为基石诞生的一个用于传输Web内容的一个网络协议,在“网络分层模型”中属于“应用层协议”的一种。在这里我们并不研究该协议标准本身,而是从安全角度去探究使用该协议传输数...

Godaddy购买SSL之后Nginx配置流程以及各种错误的解决

完整流程:参考地址:https://sg.godaddy.com/zh/help/nginx-generate-csrs-certificate-signing-requests-3601生成NGI...

Nginx从安装到高可用,一篇搞定(nginx安装与配置详解)

一、Nginx安装1、去官网http://nginx.org/下载对应的nginx包,推荐使用稳定版本2、上传nginx到linux系统3、安装依赖环境(1)安装gcc环境yuminstallgc...

阿里云免费证书申请,配置安装,使用tomcat,支持http/https访问

参数说明商品类型默认已选择云盾证书服务(无需修改)。云盾证书服务类型SSL证书服务的类型。默认已选择云盾SSL证书(无需修改),表示付费版SSL证书。如果您需要免费领取或付费扩容DV单域名证书【免费试...

你试过两步实现Nginx的规范配置吗?极速生成Nginx配置小工具

NGINX是一款轻量级的Web服务器,最强大的功能之一是能够有效地提供HTML和媒体文件等静态内容。NGINX使用异步事件驱动模型,在负载下提供可预测的性能。是当下最受欢迎的高性能的Web...

从零开始搭建HTTPS服务(搭建https网站)

搭建HTTPS服务的最初目的是为了开发微信小程序,因为wx.request只允许发起HTTPS请求,并且还必须和指定的域名进行网络通信。要从零开始搭建一个HTTPS的服务需要下面4...

群晖NAS使用官网域名和自己的域名配置SSL实现HTTPS访问

安全第一步,群晖NAS使用官网域名和自己的域名配置SSL实现HTTPS访问【新手导向】NAS本质还是一个可以随时随地访问的个人数据存储中心,我们在外网访问的时候,特别是在公网IP下,其实会面临着很多安...

让网站快速升级HTTPS协议提高安全性

为什么用HTTPS网络安全越来越受到重视,很多互联网服务网站,都已经升级改造为https协议。https协议下数据包是ssl/tcl加密的,而http包是明文传输。如果请求一旦被拦截,数据就会泄露产生...

用Https方式访问Harbor-1.9版本(https访问流程)

我上周在头条号写过一篇原创文章《Docker-Harbor&Docker-kitematic史上最详细双系统配置手册》,这篇算是它的姊妹篇吧。这篇文章也将用到我在头条写的另一篇原创文章的...

如何启用 HTTPS 并配置免费的 SSL 证书

在Linux服务器上启用HTTPS并配置免费的SSL证书(以Let'sEncrypt为例)可以通过以下步骤完成:---###**一、准备工作**1.**确保域名已解析**...

取消回复欢迎 发表评论: