Skip to content

Instantly share code, notes, and snippets.

@1901
1901 / ssh_commands.sh
Last active March 30, 2022 17:31
[SSH commands] #ssh #linux
# ssh to host
ssh user@hostname
# generate ssh key
ssh-keygen -t rsa -C "[email protected]"
# copy local ssh public key to remote host
ssh-copy-id user@hostname
# add private key to ssh-agent
@1901
1901 / redis_commands.sh
Last active October 8, 2019 04:35
[Redis commands] #redis
# 如果是通过 apt-get 或 yum 安装的 redis
/etc/init.d/redis-server stop
/etc/init.d/redis-server start
/etc/init.d/redis-server restart
# 如果是通过源码安装的 redis
./redis-cli -h 127.0.0.1 -p 6379 shutdown
./redis-cli -a 密码 -h 127.0.0.1 -p 6379 shutdown # 如果有密码
@1901
1901 / netstat_stat.sh
Created August 12, 2019 13:13
[netstat] #linux #network
# 按状态统计
netstat -nat | awk '{print $6}' | sort | uniq -c |sort -rn
# 按本机到外部80端口的访问统计
netstat -nat | grep ESTABLISHED | awk '{print $5}' | grep :80 | sort | uniq -c | sort -rn
# 按外部到本机80端口的访问统计
netstat -nat | grep ESTABLISHED | awk '{print $4}' | grep :80 | sort | uniq -c | sort -rn
# ESTABLISHED 正在通信
@1901
1901 / remove_duplicated_lines
Created July 22, 2019 08:36
[Remove duplicated lines] #sublime
1. Sort Lines.
2. Find And Replace. (确保正则模式打开)
^(.+)$[\r\n](^\1$[\r\n]{0, 1})+
\1\n
@1901
1901 / max_open_files.sh
Last active July 18, 2019 13:33
[Linux max open files] #linux
ulimit -a
ulimit -n
# check hard limit
ulimit -Hn
# check soft limit
ulimit -Sn
# current session change
@1901
1901 / firewall.sh
Last active March 17, 2020 15:34
[Firewall] #linux #firewall
# list enabled ports/services
firewall-cmd --zone=public --list-ports
firewall-cmd --zone=public --list-service
# enable http(s) port (80 443) using the firewall-cmd
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
# enable specified port
@1901
1901 / centos_disable_selinux.sh
Created July 18, 2019 10:52
[CentOS disable selinux] #linux #selinux
# check selinux status (SELinux status & Current mode)
sestatus
---
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
@1901
1901 / centos_change_hostname.sh
Last active July 18, 2019 13:33
[CentOS change hostname] #linux #hostname
# CentOS 6.x
hostname newHostName
vi /etc/sysconfig/network
# CentOS 7.x
hostnamectl set-hostname newHostName
# Change oldHostName to newHostName
vim /etc/hosts
@1901
1901 / linux_version.sh
Last active September 11, 2019 12:55
[check linux version] #linux #version
# 查看 Linux 内核版本信息
cat /proc/version
uname -a
uname -r
# 查看 Linux 系统版本信息
cat /etc/issue
@1901
1901 / yum_update_git_on_centos6.sh
Created May 16, 2019 09:30
[Update git on CentOS 6.x] #git
yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm -y
yum --disablerepo=base,updates --enablerepo=rpmforge-extras update git -y
yum update git -y
git --version