参考

查看用户

$ cat /etc/passwd

WXWorkCapture_16176602296863.png

$ w
> 当前活跃用户

查看用户组

$ cat /etc/group

3407216f020f2586aca3e3b.webp

新建用户组

$ sudo groupadd git

新建用户useradd

$ sudo useradd -s /bin/false -g git -d /opt/gogs git
> 其中
-s /bin/false	限制使用该账号登录
> 或者指定shell,作为正常账号使用
-s /bin/bash

# 另一个命令adduser
在添加用户的同事还在/home下为用户建立归属文件夹,并在里面放入各种用户自己的配置文件,比如.bashrc, .profile, GUI桌面配置文件等等

将已存在用户添加到用户组

# 修改用户帐号的各项设定。
$ usermod -a -G 组 用户名
# 为用户指定shell
$ usermod -s /bin/bash 用户名

目录权限操作

$ sudo chgrp -R 用户组 目录	//将目录归属某用户组

$ chmod -R g+r 目录		//授予用户组整个目录读权限
$ chmod g+x 目录		//授予用户组对目录本身执行权
$ chown -R 用户 目录1 目录2	//见目录归属某个用户

创建systemd服务文件

$ sudo vi /etc/systemd/system/XXXXX.service
\---------------

$ sudo systemctl daemon-reload
$ sudo systemctl start|stop|restart|status|enable|disable XXXXX
# 查看服务程序列表
$ systemctl list-units --type=service --state=active|running
https://www.tecmint.com/list-all-running-services-under-systemd-in-linux/
# 查看运行日志
$ journalctl -u service-name.service -f

防火墙设置

https://www.cnblogs.com/haoliyou/p/17339561.html

# 允许tcp访问22
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 指定来源IP
iptables -I INPUT -s 192.168.0.19 -p tcp --dport 22 -j ACCEPT

磁盘管理

# 查看磁盘使用概况
$ df -h
# 查看当前目录,深max-depth层的目录
$ du -h --max-depth=1
$ sudo lsof / | grep deleted

https://linux.cn/article-9196-1.html
https://www.cnblogs.com/yingsong/p/9468260.html

sudo切换,环境变量设置保持

https://www.baeldung.com/linux/username-not-in-sudoers-file

$ vi /etc/sudoers
# The following should be in `/etc/sudoers`. To edit `/etc/suoders` use the command `sudo visudo` in a terminal.
# *Do NOT attempt to modify the file directly*
Defaults  	env_reset
Defaults	mail_badpass
Defaults	env_keep+="http_proxy ftp_proxy git_proxy all_proxy https_proxy no_proxy" # Add this line
...

如何编辑失效的/etc/sudoers

此时无法执行 sudo su

  • 打开两个终端,以提供sudo认证
  • 获取第一个终端会话的PID
# 在第一个终端输入,查看返回PID_1
$ echo $$
  • 在第二个终端输入,向第一个终端发起认证请求
$ pkttyagent --process $PID_1
  • 查看第一个终端,出现要求输入root密码提示符。输入root密码。
  • 第二个终端获得root授权,即可进行正常编辑
$ sudo vi /etc/sudoers

查找包含指定字符串的文件

https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux

$ grep -rnw '/path/to/somewhere/' -e 'pattern'

缺少网关配置

导致ping 外网IP读报错: connect: Network is unreachable

# 查网关配置项
$ sudo route -n
仅仅显示一条

查看同网内其他主机,有多条,决定增加一条
$ sudo route add default gw 192.168.1.1
再ping,问题解决

减少window title bar的高度(ubuntu 20)

$ sudo nano ~/.config/gtk-3.0/gtk.css with following content:

https://unix.stackexchange.com/questions/276951/how-to-change-the-titlebar-height-in-standard-gtk-apps-and-those-with-headerbars

headerbar entry,
headerbar spinbutton,
headerbar button,
headerbar separator {
    margin-top: 0px; /* same as headerbar side padding for nicer proportions */
    margin-bottom: 0px;
}

headerbar {
    min-height: 24px;
    padding-left: 2px; /* same as childrens vertical margins for nicer proportions */
    padding-right: 2px;
    margin: 0px; /* same as headerbar side padding for nicer proportions */
    padding: 0px;
}

交换空间

有两种建缓冲区的方法

  • 在挂载点/下建立缓冲区文件

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04
其中涉及配置参数
$ cat /proc/sys/vm/swappiness
$ cat /proc/sys/vm/vfs_cache_pressure

$ sudo swapon --show
$ free -m
$ sudo swapoff -a
$ sudo swapon -a
# determine the UUID of the swap partition
$ sudo blkid | grep swap (or lsblk -f | grep swap) 
$ sudo nano /etc/fstab

调整磁盘分区

https://blog.csdn.net/u012608836/article/details/109353204

/usr/bin/sudo must be owned by uid 0 and have the setuid bit set

https://askubuntu.com/questions/452860/usr-bin-sudo-must-be-owned-by-uid-0-and-have-the-setuid-bit-set

ubuntu中文等配置

https://www.cnblogs.com/zhumengke/articles/11440763.html