- 創(chuàng)建非 root 用戶
# ubuntu
adduser user1
# 將用戶加入 root 組
usermod -a -G sudo user1
# centos
adduser user1
# 設(shè)置密碼
passwd user1
# 添加到 wheel 用戶組
usermod -a -G wheel user1
- ssh 秘鑰對認證
# 本地執(zhí)行
ssh-keygen # 將會生成 ~/.ssh/id_rsa.pub (公鑰) 和 ~/.ssh/id_rsa (私鑰)
# 將公鑰復(fù)制到服務(wù)器
scp -P port ~/.ssh/id_rsa.pub user@server-ip:~
# ssh 登錄服務(wù)器
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
# 將公鑰添加到 authorized_keys
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
# 修改目錄權(quán)限
chown -R user1:user1 ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
- 禁止密碼, root 用戶登錄
# 登錄服務(wù)器
vim /etc/ssh/sshd_config
# 查找
PasswordAuthentication no
PermitRootLogin no
# 重啟 ssh 服務(wù)
# ubuntu
sudo service ssh restart
# centos
sudo systemctl restart ssh.service
# centos 7
systemctl restart sshd
- 禁止 ping
vim /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_all = 0
sysctl -p
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。