关于lnmp一键安装包的那些事
好像目前nginx特别流行,我的几位友情链接都在使用nginx,所以,小荷塘最近也开始体验nginx了。而且对于nginx的内存占用效果,小荷塘感到特别震精(装好以后内存占用不到80M!!!)。
对于大部分新手来说,都是使用centOS+Licess的lnmp一键安装包的吧(其实lnmp意思就是Linux+nginx+mysql+php)。本文中的方法也是基于该环境来实现的。在折腾lnmp的过程中,我也遇到了一系列的问题,下面对这些问题作一个归总。
1,nginx下WordPress的伪静态设置
因为nginx还不完全兼容Apache,所以造成一些不便,比如不支持.htaccess(即不能伪静态),那么如何解决这个问题呢?
编辑/usr/local/nginx/conf/nginx.conf文件,在server容器中添加下面这几行: (more…)
我的SSH安全设定
分享一下自己的SSH安全设定(本文基于Ubuntu 18.04 64bit). 大概方面有3个: 1, 建立普通用户zhang3, 并授予sudo权限; 2, 禁止root登陆; 3, 禁用密码登陆, 使用pub key登陆.
1, 建立普通用户zhang3, 并授予相关权限
平时主要使用zhang3用户来登陆, 因此需要客户端的pub key交给zhang3, 让zhang3做好免密码登陆相关设定.
user=zhang3
useradd -m -s /bin/bash $user
passwd $user
# 授予用户sudo权限
echo "$user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$user
# 上传公钥, 这里我将公钥上传到$user用户的home目录
cd /home/$user
rz -bey # 选择 id_rsa.pub 上传
su - $user
mkdir ~/.ssh; \
cat id_rsa.pub >> ~/.ssh/authorized_keys && \
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
2, 设定SSH相关权限
sudo sed -i 's/^\#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
sudo sed -i 's/^\#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
sudo sed -i 's/^\#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
sudo sed -i 's/^\#\?PermitEmptyPasswords.*/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
sudo sed -i 's/^\#\?MaxAuthTries.*/MaxAuthTries 3/g' /etc/ssh/sshd_config
解释:
PermitRootLogin no #禁止root远程登陆
PubkeyAuthentication yes #启用pubkey登陆
PasswordAuthentication no #禁用密码登陆
PermitEmptyPasswords no #禁止空密码
MaxAuthTries #允许最大失败次数,默认为6
# 也可以最后再确认一下
egrep '^(PermitRoot|Pubkey|Password|MaxAuthTries)' /etc/ssh/sshd_config
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
有些老版本的sshd_config里面可能会有一项”RSAAuthentication”, 该项也表示启用pub key登陆, 但这是第1代ssh通讯协议使用的配置项, 该选项在CentOS 7及ubuntu 16.04版本以上均已弃用(如果强行加上此选项会收到一个”Deprecated option RSAAuthentication”的提示), 也可以在sshd_config里添加一项”Protocol 2″来表示使用第几代通讯协议.
2024.05.15 补充
由于操作比较麻烦, 要输入的命令比较多, 还要不停切换用户. 索性写成 Ansible playbook 好了
sudo apt update
sudo apt install git ansible # Debian 系统可能还需要安装sudo
git clone https://gist.github.com/ce794b18a58bccb432ed151abcb242ca.git
cd ce794b18a58bccb432ed151abcb242ca
vim sys.init.yaml # 改掉其中的 USERNAME 和 Pubkey 内容
ansible-playbook ./sys.init.yaml
Read More