0%

Linux常用命令

今天重新登上了自己的服务器,发现好多操作的命令都忘了,因此这里需要记录一下,后面也会补充吧。

1. 用户相关的命令

创建用户:adduser username,创建一个用户,也会在home目录下创建相应的目录;useradd username,只是创建了一个用户名,可以添加-m参数实现创建home下的目录。

修改密码:passwd username.

删除用户:userdel -r username.

为创建的用户赋予管理员权限:添加/etc/sudoers.d/username文件,添加相应用户,例如username ALL=(ALL) ALL。如果是修改/etc/passwd中相应用户的用户ID的话,登录会直接以ROOT登录,修改sudoers文件相应给到用户的权限会安全一点。

2. ssh和service

修改ssh连接端口:找到/etc/ssh/sshd_config文件,找到相应的行修改端口就行。

修改source.list文件:sudo vi /etc/apt/sources.list,添加相应的代理,最好先将原来的文件备份一个。

查看服务开启状态:sudo service --status-all.

3. 安装v2ray

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /bin/bash
# Copyright (c) 2018 flyzy小站

red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'

os='ossystem'

check_os() {
if [[ -f /etc/redhat-release ]]; then
os="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
os="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
os="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
os="centos"
elif cat /proc/version | grep -Eqi "debian"; then
os="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
os="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
os="centos"
fi
}

getversion(){
if [[ -s /etc/redhat-release ]]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}

centosversion(){
if [ ${os} == 'centos' ]
then
local code=$1
local version="$(getversion)"
local main_ver=${version%%.*}
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}

firewall_set() {
echo -e "[${green}信息${plain}] 正在设置防火墙..."
if centosversion 6; then
/etc/init.d/iptables status > /dev/null 2>&1
if [ $? -eq 0 ]; then
chkconfig iptables off
echo -e "[${green}信息${plain}] 防火墙已经关闭。"
else
echo -e "[${yellow}警告${plain}] 防火墙(iptables)好像已经停止或没有安装,如有需要请手动关闭防火墙。"
fi
elif centosversion 7; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ]; then
systemctl stop firewalld.service
systemctl disable firewalld.service
echo -e "[${green}信息${plain}] 防火墙已经关闭。"
else
echo -e "[${yellow}警告${plain}] 防火墙(iptables)好像已经停止或没有安装,如有需要请手动关闭防火墙。"
fi
fi
echo -e "[${green}信息${plain}] 防火墙设置成功。"
}

main() {
check_os
if [ ${os} == 'centos' ]
then
firewall_set
fi
bash <(curl -L -s https://install.direct/go.sh)
}

if [ "$EUID" -ne 0 ]; then
echo -e "[${red}错误${plain}] 必需以root身份运行,请使用sudo命令"
exit 1;
fi

main

4. 改变终端前缀提示

~/.bashrc文件中添加export PROMPT_COMMAND='echo Hello,Spwpun'类似这样的语句,在终端前面就会显示提示信息。

image-20200920003523225

5. tmux

tmux是一个终端复用器,开启的一个终端叫做一个session,一个session可以开启多个window,可以开启多个终端来执行AFL的并行模式。

tmux ls: 查看已有会话。

tmux new -s <session-name>:新建会话。

tmux attach -t <session-name>:接入会话。

tmux kill-session -t <session-name>:删除会话。

tmux有大量快捷键,不过需要前缀键才能使用,默认的前缀键是Ctrl+B

按完前缀键后:s(列出会话)、d(退出会话)、$(重命名当前会话)

6. 安装vulhub漏洞靶场

1
2
3
4
5
6
7
curl -s https://get.docker.com/ | sh
pip install docker-compose
git clone https://github.com/vulhub/vulhub.git
cd /path/to/vuln/
docker-compose build # 编译
docker-compose up -d # 启动环境
docker-compose down # 停止环境

7. 永久添加环境变量

1
2
3
4
5
sudo vim /etc/profile
# 在最后一行添加:
export PATH="/home/spwpun/.local/bin:$PATH"
# 退出后使用source命令生效
source /etc/profile

8. 查看一个目录下各个文件的大小

du -h --max-depth=1 /var/lib/docker

9. docker与主机之间复制文件

sudo docker ps -a,查看docker的所有容器实例,包含运行的和停止的

sudo docker cp host_path containerID:container_path

sudo docker cp containerID:container_path host_path

10. docker启动容器命令

sudo docker run -i(image) -t(tag) Ubuntu:16.04 "/bin/bash",不输入tag的时候会自动设为latest.

11. docker容器重命名

docker rename [旧容器名] [新容器名]

docker中的容器和镜像是两个概念,适当看一下是否创建了很多无用的容器,那样会很占内存的。

12. google everything…