一、查看系统的版本信息
1.系统版本:
[root@oldedu59 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@oldedu59 ~]# ll /etc/redhat-release
lrwxrwxrwx. 1 root root 14 Mar 26 11:39 /etc/redhat-release -> centos-release
[root@oldedu59 ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
[root@oldedu59 ~]#
2.内核版本:
[root@oldedu59 ~]# uname -r
3.10.0-957.el7.x86_64
[root@oldedu59 ~]# uname -m
x86_64
二、添加用户 修改密码 查看用户 删除用户
1.添加用户 useradd oldboy
[root@oldedu59 /]# useradd oldboy
2.查看用户 id
[root@oldedu59 /]# id oldboy
uid=1000(oldboy) gid=1000(oldboy) groups=1000(oldboy)
3. 修改密码
passwd--stdin
从标准输入获取密码(从管道获取密码)
非交互设置密码
[root@oldedu59 ~]# echo 123456| passwd --stdin oldboy
Changing password for user oldboy.
passwd: all authentication tokens updated successfully.
[oldboy@oldedu59 ~]$ echo 123456| passwd --stdin oldboy
Only root can do that.
4.切换用户 su
[root@oldedu59 ~]# su - oldboy
Last login: Mon Apr 15 09:24:39 CST 2019 on pts/0
5.删除用户 userdel
三、修改环境变量 PS1
1.常见环境变量
PATH:存放的是命令的位置/路径
[root@oldedu59 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@oldboyedu59 ~]# PATH=
[root@oldboyedu59 ~]# echo $PATH
[root@oldboyedu59 ~]# find
-bash: fing: No such file or directory
[root@oldboyedu59 ~]# awk
-bash: awk: No such file or directory
[root@oldboyedu59 ~]# sed
-bash: sed: No such file or directory
[root@oldboyedu59 ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@oldboyedu59 ~]# find
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history
./.viminfo
./2.txt
PS1:控制命令行格式:
[root@oldboyedu59 ~]# echo $PS1
[\u@\h \W]\$
2.临时的--重新登录系统失效
[root@oldedu59 ~]#export PS1='[\u@\h \w]\$'
[root@oldedu59 ~]#cd /etc/sysconfig/network-scripts/
[root@oldedu59 /etc/sysconfig/network-scripts]#
3.永久--写入到/etc/profile与生效
[root@oldboyedu59 ~]# export PS1='[\u@\h \w]\$'
[root@oldboyedu59 ~]#cd /etc/sysconfig/network-scripts/
[root@oldboyedu59 /etc/sysconfig/network-scripts]#cd
[root@oldboyedu59 ~]#source /etc/profile
4.检查:
[root@oldboyedu59 ~]#echo $PS1
[\u@\h \w]\$
四、SELinux:增强型Linux(安全);NSA(美国国家安全局);限制root和普通用户权限
1.关闭SELinux
注意:操作前备份 操作后检查
cp /etc/selinux/config /etc/selinux/config.bak
永久--->修改配置文件 :/etc/selinux/config服务器重启之后生效
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of disabled.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #将SELINUX=右边改为disabled即可
SELINUX=右边可以写什么:
SELINUX=右边可以写什么
SELINUX=enforcing SELinux开启
SELINUX=permissive SELinux关闭 还会有警告信息
SELINUX=disabled SELinux彻底关闭
临时--->setenforce重启服务器后失效
[root@oldedu59 ~]# getenforce #getenforce 查看SELinux状态
Disabled
[root@oldedu59 ~]# setenforce #setenforce 修改SELinux状态
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldedu59 ~]# setenforce 0 #setenforce 0 临时关闭
setenforce: SELinux is disabled
五、防火墙【firewalld(C7) iptables(C6 )】
1.作用
根据我们设置的规则 准许/禁止用户进出
2.是否需要开启?
服务器有公网ip地址--->开启防火墙
服务器没有公网ip 局域网;并发访问量太高--->关闭防火墙
3.如何关闭?
临时--->systemctl stop firewalld重启服务器失效
start 开启
[root@oldedu59 ~]# systemctl stop firewalld
永久--->systemctl disable firewalld
enable 永久开启
[root@oldboyedu59 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
检查 systemctl status firewalld
[root@oldedu59 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
六、配置yum源
1.yum源
软件的下载仓库
(1)阿里云仓库
(2)清华仓库
(3)镜像网站
2.如何修改yum源
将系统默认的---->修改为阿里云
(1)打开阿里云网站mirrors.aliyun.com
(2)找到CentOS
[root@oldedu59 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2523 100 2523 0 0 43821 0 --:--:-- --:--:-- --:--:-- 45053
3.如何增加epel源
(1)系统默认的: base extras updates
增加epel源
[root@oldboyedu59 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,019
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 385
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,511
repolist: 11,915