一、常用命令
1、修改主机名
hostnamectl set-hostname 主机名 2、防火墙
打开防火墙
systemctl start firewalld 设置防火墙开机启动
systemctl enable firewalld 查看防火墙状态
systemctl status firewalld 查看开放的端口
firewall-cmd --list-ports 或
netstat -ntlp 添加开放端口
firewall-cmd --zone=public --add-port=18010/tcp --permanent
firewall-cmd --reload3、创建新用户并分配权限
3.1、创建新用户
创建一个用户名为:cheng
[root@localhost ~]# adduser cheng 为这个用户初始化秘密,linux会判断密码复杂度,不过可以强行忽略
[root@localhost ~]# passwd cheng
更改用户 cheng 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。3.2、授权
个人用户的权限只可以在本home下完成权限,其他目录别人授权。而经常需要root用户的权限,这时候sudo可以化身为root来操作。新创建的用户并不能使用sudo命令,需要给它添加授权,sudo命令的授权管理在sudoers文件里的,sudoers文件只有读的权限,如果要写需要加入权限
[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers // 查找sudoers的路径
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz找到这个文件位置之后再查看权限
[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers发现只有读的权限,如果要修改,需要先添加w权限
[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)然后就可以添加内容,在下面的一行追加新增的用户:
[root@localhost ~]# vim /etc/sudoers
## Allow root to run any commands anywher
root ALL=(ALL) ALL
cheng ALL=(ALL) ALL #这个是新增的用户wq保存退出,收回sudoers的写入权限:
[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)这时新用户登录就可以使用sudo了
[cheng@localhost ~]$ sudo cat /etc/passwd
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.第一次使用会提示你,你已经化身超人,身负责任。而且需要密码才可以下一步,如果不想需要输入密码,可以将最后一个ALL修改成NOPASSWD:ALL。
3.3、删除用户
userdel -rf cheng:删除名称为cheng的用户 然后就可以ls -l /home查看,会返现cheng用户没有了
4、curl命令
4.1、curl post请求发送json数据
curl -X POST -H "Content-Type: application/json" http://api.zhihe.mobi/v2/getjson -d '{"param":"20210608"}' 如果还需要其他请求头参数,使用-H参数来追加,例如,添加refer参数:
curl -X POST -H "Content-Type: application/json" -H "referer:http://localhost" http://api.zhihe.mobi/v2/getjson -d '{"param":"20210608"}' 4.2、curl post发送json数据,且json数据内容在文件中
步骤一:在执行路径下,新建文件如param.json
{"param":"20210608"} 说明:文件中的内容为json参数内容,无需进行转义
步骤二: 执行命令
curl -X POST -H "Content-Type: application/json" -H "referer:http://localhost" http://localhost:8080/test/file/import -d @param.json 5、查询打开的连接数
netstat -an | grep ESTABLISHED | wc -l6、查询分类统计的连接数
netstat -an|awk '/^tcp/ {++s[$NF]} END {for(a in s ) print a,s[a]}'
LISTEN 9
CLOSE_WAIT 2
ESTABLISHED 148
TIME_WAIT 4851二、必备软件
yum -y install net-tools gcc make gcc-c++ openssl-devel wget vim lrzsz unzip git
评论区