14 Master Linux

14.1 miscellaneous

  • when you always see a system alert, sudo rm /var/crash/*
  • If you find something wrong abount SSH, ensure that the user’s login shell is /bin/bash.
  • unar (lsar) 可自动解决 .zip 乱码问题
  • understanding ~/.bashrc

14.2 inspect and monitor

  • system version
uname -r                       # kernel version
cat /etc/debian_version        # Debian version
cat /etc/lsb-release           # especially useful for Docker image
  • cpu
grep 'physical id' /proc/cpuinfo | sort -u          # processors
grep 'core id'     /proc/cpuinfo | sort -u | wc -l  # cores per processors
grep 'processor'   /proc/cpuinfo | sort -u | wc -l  # threads
  • port and traffic
sudo lsof -i -P -n | grep LISTEN    # IPv4/6, ssh -> 22, localhost -> 127.0.0.1
netstat -tulpn      # tcp, udp, listen, show process, ssh -> 22
sudo iftop -P
sudo tcptrack -i wlp2s0  # port 1080
  • file system
du . -d 1 -h
df -h
sudo blkid
lsblk # -f
  • process
ps -aux  # 观察系统所有的程序数据
ps -axjf # 连同部分程序树状态
pstree

14.3 account

  • add account

Don’t use -p password, it’s wrong and unsafe. Because it saves the password directly instead of hashed code into /etc/shadow 19.

sudo useradd -m -s /bin/bash username  
echo 'username:password' | sudo chpasswd
  • group

Add user to sudo group (wheel for CentOS) can assign root privilege.

sudo usermod -g group username                       # change initial group
sudo usermod [-a] -G group1, group2 username      # append or change
  • others
    • In man page, LOGIN (-l option) means username
    • id, who

  1. You can use sudo grep username /etc/shadow to verify, note that password is shown unencrypted.↩︎