太久没碰 Linux ,上机后总是一脸懵逼,不知道该干啥,记录一下上机之后该做的几件事

环境确认

上机第一件事应该确认机器的基本信息

  • uname -a cat /proc/version cat /etc/issue机器版本
  • w当前状态
  • cat /proc/cpuinfocpu信息
  • free内存信息
  • df磁盘信息
  • ifconfig网络信息
  • ps top进程信息
  • crontab -l less /etc/crontab定时任务
  • service --status-all systemctl服务

安全

ssh关闭密码登录及端口修改

  • ssh-keygen -t rsa -b 4096生成密钥对
  • 将自己公钥添加到~/.authorized_keys,并修改文件权限chmod 600 ~/.ssh/authorized_keys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 编辑 sshd_config 文件
vim /etc/ssh/sshd_config

# 禁用密码验证
PasswordAuthentication no
# 启用密钥验证
RSAAuthentication yes
PubkeyAuthentication yes
# 指定公钥数据库文件
AuthorsizedKeysFile .ssh/authorized_keys

# 快速替换命令
sed -i "s/^PasswordAuthentication.*/PasswordAuthentication no/g" /etc/ssh/sshd_config
sed -i "s/^#RSAAuthentication.*/RSAAuthentication yes/g" /etc/ssh/sshd_config
sed -i "s/^#PubkeyAuthentication.*/PubkeyAuthentication yes/g" /etc/ssh/sshd_config
sed -i "s/^#AuthorizedKeysFile.*/AuthorizedKeysFile .ssh\/authorized_keys/g" /etc/ssh/sshd_config
  • 注意检查防火墙新端口是否放行,不然要被关在外面了
  • 重启ssh服务
1
2
3
systemctl restart sshd.service
service sshd restart
/etc/init.d/ssh restart

环境安装

  • install script

其他常用片段

  • add ssh key
  • add swap file
  • supervisor

ssh 配置

为单独的网站配置sshkey.ssh/config

1
2
3
4
# github
Host github.com
HostName github.com
IdentityFile ~/.ssh/github_id_rsa

cron 配置

  • vim /var/spool/cron/crontabs/root
  • chmod 600 /var/spool/cron/crontabs/root修改权限
  • cat /var/log/syslog查看 crontabs 日志
1
2
3
4
5
6
7
8
9
10
11
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

# 每 5 分钟运行
*/5 * * * * LANG=en_US.UTF-8 python3 main.py >> /log/log.log 2>&1

nginx