基础环境
#当前系统版本信息
[root@real ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
#系统内核版本号
[root@real ~]# uname -r
3.10.0-862.el7.x86_64
#查看系统位数
[root@real ~]# uname -m
x86_64
CentOS7systemctl补全服务名称
yum install bash-completion -y
关闭防火墙
[root@real ~]# systemctl stop firewalld.service
#取消开机自启
[root@real ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
关闭SElinux功能
[root@real ~]# vim /etc/selinux/config
SELINUX=disabled #修改
重启才会生效
[root@real ~]# getenforce #查看SELinux当前的级别状态
Disabled
使用网易163镜像做yum源
1.备份
[root@real ~]# cd /etc/yum.repos.d/
[root@real yum.repos.d]#
[root@real yum.repos.d]# mkdir backup
[root@real yum.repos.d]# mv C* backup
2.下载163yum源
[root@real yum.repos.d]#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
或阿里云yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.清理旧缓存
[root@real yum.repos.d]# yum clean all
4.创建新缓存
[root@real yum.repos.d]# yum makecache
5.安装必要的软件包
yum -y install tree nmap sysstat gcc gcc-c++ make telnet
相关服务设置开机自启
查看服务是否开机自启
[root@real ~]# systemctl list-unit-files | egrep "sshd.service|crond.service|rsyslog.service|sysstat.service|^NetworkManager.service"
crond.service enabled
NetworkManager.service enabled
rsyslog.service enabled
sshd.service enabled
sysstat.service enabled
sysstat 服务会自动每隔10分钟收集一次系统状态信息,并将它们存储到 /var/log/sa目录下。每天一个文件,文件名分别是sa01, sa02,... sa30..
设置开机自启命令
systemctl enable xxx.service
取消开机自启
systemctl disable xxx.service
更改SSH服务端远程登录配置
[root@real ~]# cat /etc/ssh/sshd_config |egrep "^#Port"
#Port 22 #取消注释,换成其他端口,平时实验不用修改
Port:代表端口,后边的数字代表sshd服务监听的是哪个端口
PermitRootLogin :yes代表允许root用户远程登录,no代表不允许(如果是no则所有远程登陆连接都不能用root用户登陆,普通用户可以正常连接)
PermitEmptyPasswords:yes代表允许用户输入空的登陆密码,no代表不允许
UseDNS:指定sshd是否应该对远程主机名进行反向解析,以此检查此主机名是否与IP地址真实对应。默认值“yes”, 建议改成“no”,否则可能会导致SSH连接很慢
GSSAPIAuthentication 设置为no
平滑重启sshd服务
[root@real ~]# systemctl reload sshd.service
调整历史记录以及终端超时
临时生效:
export TMOUT=300:连接超时时间控制变量
export TMOUT=3:3秒之后,没有任何输入,则自动退出。
expoort HISTSIZE=5:history size 命令行历史记录数量,history命令显示的条数
export HISTFILESIZE=5:命令行命令对应的历史记录文件,文件中命令记录数
永久生效:
写入/etc/profile中
source /etc/profile生效
隐藏Linux内核和版本信息
centos7启动后会显示版本信息、内核信息
备份显示系统版本和内核的文件
[root@real ~]# cp /etc/issue{,.bak}
[root@real ~]# cp /etc/issue.net{,.bak}
清空文件
[root@real ~]# > /etc/issue
[root@real ~]# > /etc/issue.net
[root@real ~]# cat /etc/issue
[root@real ~]# cat /etc/issue.net
再次登录,不显示系统版本信息和内核信息