# Linux常用操作
# 设置盖上盖子不休眠
- 编辑文件/etc/systemd/logind.conf
$ vi /etc/systemd/logind.conf
将
#HandleLidSwitch=suspend
改为HandleLidSwitch=lock
重启服务生效
$ systemctl restart systemd-logind
# 设置密钥登录
CentOS 7.6
- 上传或者生成密钥
- 本地上传
scp -P <端口> id_rsa.pub root@<服务器地址>:~
- 生成
ssh-keygen -t rsa -C "xxxxxxx@email.com" -f ./id_rsa
- 安装并设置密钥权限
mkdir -p /root/.ssh && cd /root/.ssh \
&& cat ~/id_rsa.pub >> authorized_keys \
&& chmod 600 authorized_keys \
&& chmod 700 ~/.ssh
- 备份配置文件
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
- 删除配置项
sed -i '/PasswordAuthentication.*/d' /etc/ssh/sshd_config \
&& sed -i '/PubkeyAuthentication.*/d' /etc/ssh/sshd_config \
&& sed -i '/RSAAuthentication.*/d' /etc/ssh/sshd_config \
&& sed -i '/AuthorizedKeysFile.*/d' /etc/ssh/sshd_config
- 以追加内容的方式新增配置
echo PasswordAuthentication no >> /etc/ssh/sshd_config \
&& echo PubkeyAuthentication yes >> /etc/ssh/sshd_config \
&& echo RSAAuthentication yes >> /etc/ssh/sshd_config \
&& echo AuthorizedKeysFile .ssh/authorized_keys >> /etc/ssh/sshd_config
- 重启sshd服务
systemctl restart sshd
← Linux常见命令 Tail查看日志命令 →