Linux 配置,命令

服务器配置

添加管理员用户

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
# useradd test
# passwd test
# mkdir -p /home/test/.ssh
# chown 600 /home/test/.ssh/
# vim /etc/sudoers
# cd /home/test/.ssh/
# rz
# # Received /Users/uiste/.ssh/id_rsa.pub
# ls
# mv id_rsa.pub authorized_keys
# ls -al
# chown test:test authorized_keys
# chmod 700 authorized_keys
# ls -al
# chmod 600 authorized_keys
# ls
# pwd
# chown test:test /home/test/.ssh
# ls -al /home/test/

# 自定义生成ssh key
root@iZbp1bb2egi7vzn29c1dhvZ ~]# su - www
上一次登录:二 1月 1 22:49:16 CST 2019pts/1 上
[www@iZbp1bb2egi7vzn29c1dhvZ ~]$ sudo su -
Last login: Tue Jan 1 22:49:46 CST 2019 from 223.167.32.98 on pts/2
[root@iZbp1bb2egi7vzn29c1dhvZ ~]# su - www
Last login: Tue Jan 1 22:50:58 CST 2019 on pts/2
[www@iZbp1bb2egi7vzn29c1dhvZ ~]$ ssh-keygen -t rsa


# useradd test

修改管理员配置
# vim /etc/sudoers

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
test ALL=(ALL) NOPASSWD: ALL

切换用户

1
2
3
4
5
# 切换自定用户
# su - test

# 切换root用户
# sudo su -

配置SSH

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
chown test:test /home/test/
chmod 755 /home/test/.ssh/

[test@izbp14s0hny0qt9wghm6lcz .ssh]$ ls -al
total 12
drwxr-xr-x 2 test test 4096 Sep 26 10:54 .
drwx------ 3 test test 4096 Sep 26 10:44 ..
-rw------- 1 test test 411 Sep 26 10:36 authorized_keys

[test@izbp14s0hny0qt9wghm6lcz .ssh]$ cat authorized_keys
ssh-rsa AAAAB3Nza...E27svfEF6qsVb9B5dooFFFS5hNjyJJma8dyCLzmpAKXH......8XDB+ofAZYkF/7NyU9ON0OwkKWJL4jL570kfazGgJQQwrjWh5x5.....nLsLvQB2rnjbeyV+RXnNemMutokrjIgrT Administrator@PC-20180613WOHL
```

## 常用命令
* 递归创建文件夹
`mkdir -p /data/yiilogs/`

* 修改文件夹用户
`chown test:test /data/yiilogs/`

* 修改文件读写权限
`chmod 777 /data/yiilogs/`

* 查看端口占用情况
`netstat -tunlp | grep 3306`

* 匹配log中自定内容信息

tail -f /data/yiilog/xxx/access_app_nginx.log |grep ‘interface-loan/xxx’
`