416 字
2 分钟
Linux 备忘录
2019-12-20
太久没碰 Linux ,上机后总是一脸懵逼,不知道该干啥,记录一下上机之后该做的几件事
环境确认
上机第一件事应该确认机器的基本信息
uname -a
cat /proc/version
cat /etc/issue
机器版本w
当前状态cat /proc/cpuinfo
cpu信息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
# 编辑 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服务
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
# 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 日志
# 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
- 辅助配置网站crontab guru