Linux 常用命令(防火墙,用户组,MD5等)

base

# 获取函数返回值或者上一个命令的退出状态
md5sum -c --status filename.md5
echo $?

# 获取结果的第 1 行,第 2ps -ef | grep tomcat | sed -n '1p' | awk '{print $2}'
ps -ef | grep tomcat | awk 'NR>=1' | awk '{print $2}'
ps -ef | grep tomcat | grep -v 'grep.*color=auto' | awk '{print $2}'

# 命令输出结果作为输入参数
ps -ef | grep tomcat | grep -v 'grep.*color=auto' | awk '{print $2}' | xargs kill -9

end

 

shell 常用设置命令

# 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

# 替换阿里 yummv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# mv /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.backup
# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum makecache

# 安装 vim
yum -y install vim

# 关闭连接 ssh 时的 DNS 查询
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
systemctl restart sshd

# 关闭 selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 关闭系统提示音
sed -i 's/#set bell-style none/set bell-style none/g' /etc/inputrc

# 关闭 Vim 提示音
# sed -i '$a\setterm -blength 0' /etc/bashrc
echo ':set vb t_vb=' > ~/.vimrc

end

 

apt

# 语言 https://www.debian.org/doc/manuals/debian-reference/ch08.zh-cn.html
sudo dpkg-reconfigure locales

# 换源 https://mirrors.ustc.edu.cn/help/ubuntu.html
# sources.list 格式
sudo sed -i -E 's@(deb|security|ftp).debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
# DEB822 格式
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources

# 别名
echo -e "\nalias ll=\"ls -AlhX\"" >> ~/.bashrc

# 安装 vim,https://github.com/amix/vimrc
sudo apt update
sudo apt install vim -y

# 安装 jdk8
sudo vim /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/debian sid main
sudo apt update
sudo apt install -y openjdk-8-jdk

# nodejs 和 npm,https://github.com/nodesource/distributions
sudo apt install curl
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
npm config set registry https://registry.npmmirror.com

# python
sudo apt install -y python3-pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# man gcc
sudo vim /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/debian buster-backports main non-free contrib
sudo apt update
sudo apt install gcc-doc

end

 

结束用户登录

# 查看
w
# 结束 pts/0
pkill -kill -t pts/0

end

 

关闭 SSH 连接时的 DNS 解析

# 编辑配置文件,修改如下配置项
# GSSAPIAuthentication:基于 GSSAPI 的用户认证
# UseDNS:利用 DNS 解析,防止客户端欺骗
vim /etc/ssh/sshd_config

GSSAPIAuthentication no
UseDNS no

# 重启服务
systemctl restart sshd

end

 

时间(centos8 无法使用,请使用 chrony:https://www.cnblogs.com/jhxxb/p/11526098.html

yum -y install ntpdate
ntpdate ntp.aliyun.com

end

 

用户,用户组

https://www.htcp.net/2746.html

# 修改文件或文件夹所属的用户和用户组
chown -R jenkins:jenkins ./jenkins/

# 修改文件或文件夹的权限
chmod -R 0777 ./jdk1.8.0_251/

# 查看所有用户
# cat /etc/passwd | grep -v nologin | grep -v halt | grep -v shutdown | awk -F":" '{ print $1"|"$3"|"$4 }' | more
cat /etc/passwd
# jenkins:x:998:996:Jenkins Automation Server:/var/lib/jenkins:/bin/false

# 修改用户目录
usermod -d /opt/jenkins/ -u 998 jenkins
# jenkins:x:998:996:Jenkins Automation Server:/opt/jenkins/:/bin/false

end

 

MD5

# 查看文件 md5 值
md5sum filename

# 查看文件 sha1 值
sha1sum filename

# 查看文件 sha256 值
sha256sum filename

# 查看当前目录下所有文件的 md5 值
md5sum *

end

 

修改主机名

# 查看主机名
cat /etc/hostname
hostname

# 修改主机名(非临时)
vim /etc/hostname
hostnamectl set-hostname xxxx

end

 

awk:https://coolshell.cn/articles/9070.html

sed:https://coolshell.cn/articles/9104.html


https://www.cnblogs.com/jhxxb/p/10573957.html

https://coolshell.cn/articles/8883.html

https://coolshell.cn/articles/19219.html

https://github.com/jaywcjlove/linux-command

posted @ 2020-03-30 01:32  江湖小小白  阅读(944)  评论(0编辑  收藏  举报