文章目录
- 用户操作
- 添加用户组
- 添加用户,指定用户组
- 修改用户密码
- 删除用户
- 文件权限操作
- 添加文件夹
- 更改所属组 chgrp
- 更改文件的所属主 chown
- 下载依赖的 rpm 包
- 能上网的 linux 系统上下载 rpm 包
- 下载后上传到目标服务器
- 防火墙配置
- 关闭 selinux
- 临时关闭
- 生成 /etc/sysconfig/iptables 文件(如果没有)
- 保存 /etc/sysconfig/iptables 文件
- 修改配置文件
- 在文件中添加新的配置
- 加载 iptables 已保存的配置
- 查看当前防火墙状态
- 设置开机启动脚本
- 可按账号配置启动脚本(因为某些命令需要root权限才能执行)
- root 账号下配置
- 自定义账号(dpc)下配置
- 安装unzip命令
- 下载rpm文件
- 安装
- 验证
用户操作
添加用户组
groupadd dpc
添加用户,指定用户组
useradd -g dpc dpc
修改用户密码
passwd dpc
删除用户
userdel dpc
添加 -r 参数可删除对应用户文件
文件权限操作
添加文件夹
mkdir /DATA
更改所属组 chgrp
chgrp dpc /DATA/
对于文件夹可添加 -r 参数作用于文件夹及其子文件夹所有
更改文件的所属主 chown
chown dpc /DATA/
对于文件夹可添加 -r 参数作用于文件夹及其子文件夹所有
下载依赖的 rpm 包
能上网的 linux 系统上下载 rpm 包
yumdownloader 命令下载 rpm 包及其依赖
# 安装yum-utils
$ yum -y install yum-utils
# 下载 gcc 依赖包
$ yumdownloader --resolve --destdir=/rpm gcc
# 参数说明:
# –destdir:指定 rpm 包下载目录(不指定时,默认为当前目录)
# –resolve:下载依赖的 rpm 包。
下载后上传到目标服务器
进入目录,执行 rpm 安装即可
# 请使用 root 账号执行
$> rpm -ivh *.rpm --nodeps --force
防火墙配置
关闭 selinux
$> vi /etc/selinux/config
把’SELINUX=enforcing’改成’SELINUX=disabled’,然后重启机器。
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
临时关闭
$> getenforce
Enforcing
$> setenforce 0
$> getenforce
Permissive
getenforce命令可以得到selinux的状态,其中有两种(Enforcing|Permissive),前者表示开放,后者表示关闭,但是会发出警告。setenforce用来设置selinux的状态,后面跟0则设置成Permissive后面跟1设置成Enforcing。关闭selinux的命令为setenforce 0,但是这只是临时关闭,重启后恢复,想要永久生效,请更改配置文件/etc/selinux/config
生成 /etc/sysconfig/iptables 文件(如果没有)
iptables -A INPUT -s 172.24.131.48/32 -j ACCEPT
iptables -A OUTPUT -d 172.24.131.48/32 -j ACCEPT
以上代码执行后重启将失效,可通过 iptables-save 保存到文件
保存 /etc/sysconfig/iptables 文件
iptables-save > /etc/sysconfig/iptables
修改配置文件
vim /etc/sysconfig/iptables
在文件中添加新的配置
-A INPUT -s 172.24.131.48/32 -j ACCEPT
-A OUTPUT -d 172.24.131.48/32 -j ACCEPT
加载 iptables 已保存的配置
iptables-restore < /etc/sysconfig/iptables
查看当前防火墙状态
iptables -L
设置开机启动脚本
crontab -e
可按账号配置启动脚本(因为某些命令需要root权限才能执行)
root 账号下配置
@reboot /DATA/reboot_script_root.sh
自定义账号(dpc)下配置
@reboot /DATA/reboot_script_dpc.sh
安装unzip命令
下载rpm文件
到https://www.rpmfind.net/linux/rpm2html/search.php?query=unzip&submit=Search+…&system=centos&arch=下载对应发行版的对应 rpm 文件
安装
rpm -ivh unzip-6.0-22.el7_9.x86_64.rpm
这里使用 unzip-6.0-22.el7_9.x86_64.rpm (unzip 的 el7 版本进行安装),下载链接中查询可能找不到 el7 版本了,可通过其他渠道下载.
验证
unzip -v