Linux 用户管理

用户列表

1
cut -d: -f1 /etc/passwd

创建用户

1
2
3
4
adduser -m username

# 设置密码
passwd username

修改用户目录

1
usermod -m -d /newhome/username username

修改用户目录并迁移文件

1
usermod -m -d /newhome/username username

删除用户

1
userdel -r username

密码管理

检查密码是否过期

1
chage -l username

设置密码不过期

1
chage -M -1 username

SSH

OpenSSH

  • Remote operations are done using ssh, scp, and sftp.
  • Key management with ssh-add, ssh-keysign, ssh-keyscan, and ssh-keygen.
  • The service side consists of sshd, sftp-server, and ssh-agent.

基本用法

ssh root@ipssh -l root -p 22 ip

  • -l Specifies the user to log in as on the remote machine.
  • -p Port to connect to on the remote host.
  • -f Requests ssh to go to background just before command execution.
  • -C Requests compression of all data.
  • -N Do not execute a remote command. This is useful for just forwarding ports.
  • -R remote (server) host are to be forwarded to the local side.
  • -L local (client) host are to be forwarded to the given host and port, or Unix socket, on the remote side.

重启

1
2
3
service sshd restart

systemctl restart sshd

相关配置

1
grep -v '^\s*$\|^\s*\#' /etc/ssh/sshd_config

UsePrivilegeSeparation

连接慢

1
2
GSSAPIAuthentication no
UseDNS no

修改端口

https://www.cyberciti.biz/faq/howto-change-ssh-port-on-linux-or-unix-server/

免密码登录

  1. 生成公钥
1
2
cd ~/.ssh
ssh-keygen -t rsa
  1. 传输公钥至服务器
1
2
scp id_rsa.pub root@ip:~/.ssh
cat id_rsa.pub >> authorized_keys

ssh-keyscan

1
ssh-keyscan -H -t rsa ip >> known_hosts
1
2
cat /var/run/sshd.pid
kill $(cat /var/run/sshd.pid)

idle timeout for OpenSSH

端口转发

1
ssh -N -L*:80:localhost:9600 root@localhost

autossh 自动重连

主页 https://www.harding.motd.ca/autossh/
文档 https://www.harding.motd.ca/autossh/README.txt

安装

1
2
Linux   yum -y install autossh
macOS brew install autossh

使用

1
2
3
4
autossh -M 10010 -N root@ip

autossh -M 5122 -N -L2001:localhost:22 root@ip
ssh root@127.0.0.1 -p 2001

https://stackoverflow.com/questions/25084288/keep-ssh-session-alive

ssh NAT traversal

1
2
3
4
5
6
7
ssh -N -R8887:localhost:8000 root@ip
ssh root@ip
ssh -N -L*:80:localhost:8887 root@localhost
http://ip/

autossh -M 5122 -N -L2001:localhost:22 root@localhost
ssh -N -L*:80:localhost:8887 root@localhost

sftp

Compared to the SCP protocol, which only allows file transfers, the SFTP protocol allows for a range of operations on remote files which make it more like a remote file system protocol. An SFTP client’s extra capabilities include resuming interrupted transfers, directory listings, and remote file removal.

参考

中国社会问题

人口

全面放开二胎后,2016年净增人口升至906万,此后断崖式下跌:

  • 2018年净增人口为530万人
  • 2019年467万人
  • 2020年腰斩到204万人
  • 2021年腰斩之后再腰斩,仅净增48万人

就业

  • 2021年中国高校毕业生首次突破1000万人。
  • 2022年中国研究生考试报考人数达457万人,比2021年增加80万,创历史新高。
  • 2022年中国国家公务员考试报名人数突破200万,创历史新高。

健康

吸烟率

  • 2018年中国15岁以上人群吸烟率高达26.6%,其中男性吸烟率为50.5%
  • 2020年中国烟草行业工商税利总额1万2803亿元
  • 中国每年因吸烟死亡超百万人

过劳死

参考

社会矛盾

2021年11月13日,广州保安捅人事件

2021年10月10日,欧金中案

2021年6月7日,复旦大学杀人事件

2008年7月1日,杨佳袭警案

人口贩卖

刘学州事件

徐州妇女拐卖案

奇闻乱象

奇闻不断

乱象从生