本人系統為CentOS 8
可通過 命令 cat /etc/redhat-release 查看自己系統版本
[root@EasygoingEssential-VM /]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
[root@EasygoingEssential-VM /]#
命令 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 ::
#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
在最后面加上PS1=’[[\e[32m]\u[\e[0m][\e[35m]@[\e[0m][\e[33m]\h[\e[0m][\e[36m] \W[\e[0m]]$'
PS1='[\[\e[32m\]\u\[\e[0m\]\[\e[35m\]@\[\e[0m\]\[\e[33m\]\h\[\e[0m\]\[\e[36m\] \W\[\e[0m\]]\$'
最后
source /etc/profile 更新檔案,可以看到命令列顏色已變化,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/287840.html
標籤:其他
上一篇:安裝nginx并進行配置(記錄來源于馬哥linux運維教程 三)
下一篇:架構套路總結
