线下常用命令
- 改密码
修改 ssh 密码:
passwd username
修改数据库密码:
find .| xargs grep “password”
mysql -uusernname -ppassword
set password for username@localhost = password('xxx')
- 备份
- 备份网站:
cd /var/www/html
tar -zcvf ~/html.tar.gz *
上备份:
rm -rf /var/www/html
tar -zxvf ~html.tar.gz -C /var/www/html
- 备份数据库:
show databases;
mysqldump -u username -p databasename >~/bak.sql
mysqldump -u username -p --all-databases >~/bak.sql
上备份:
create database xxx;
use xxx;
source ~/bak.sql;
或者
cd
mysql -uroot -p xxx<~bak.sql
- 重要文件
- /etc/passwd
这个文件记录当下系统中所有用户的相关信息
cat /etc/passwd
- 日志文件
获取 web 日志的绝对路径,在配置文件中找到路径,配置文件有:nginx.conf(nginx), httpd.conf(apache), web.xml(java), config_default.py(python)
find / -name “nginx.conf” # 获得路径
# 在配置文件中可以看到
acces_log =
error_log =
- 设定关键文件不允许被修改
chattr +i /etc/password # 设定这个文件不被修改
chattr -R +i /var/www/html # 设定文件夹下所有的文件不被修改
- 扫描
- nmap
nmap xx.xx.xx.xx/24 # 扫描网段
nmap -sV xx.xx.xx.xx # 扫描服务版本
nmap -O xx.xx.xx.xx/24 # 探测操作系统
- tcpdump
可以实现流量监控
tcpdump # 默认监听第一张网卡的流量
tcpdump host xx.xx.xx.xx # 监听目标主机收到和发送的包
tcpdump -i lo port80 -w flow.pcap
- find 命令
- 一般形式
find path -option[name, ctime]
find .|xargs grep "password"
- 管道命令 “|”
cat /etc/passwd | grep root
以上面的命令为例,右边的命令接受左边的输出为参数,即左边的标准输出转化右边的标准输出 - xargs
有些命令不能的参数只能从接受命令行参数,所有只使用 “|” 是不行的。加上‘xargs’可以使左边命令的标准输出转化为右边命令的命令行参数。
比如:echo "hello world" | xargs echo
xargs 一般是和管道符一起使用的,单独使用的时候默认为xargs echo
, xargs 可以和其他的命令一起使用,比如:
xargs find / -name # 等待输入参数
*.txt
./foo.txt
./hello.txt
xargs 与别的命令一起使用时会等待参数输入,输入参数后返回结果。
- 端口命令
netstat -an|grep port # 查看端口状态
nc -vvlp port # 监听端口
nc -lp port & #打开端口
-
ls
ls -alt
,
-a 表示全部文件,-l 显示文件的详细信息,-t 按照文件创建时间排序 -
关于进程的命令
lsof 文件名
#查看文件被哪些进程读写
lsof -i :port
#查看端口 port 有哪些进程在运行
lsof -c process
#查看进程 process 当前占用了哪些文件
lsof -g gid
#显示归属 gid 的进程的文件占用情况
kill -9 pid
#强制杀死进程