linux 初始化服务器

Last updated on November 20, 2024 am

🧙 Questions

新到手的服务器,如何初始化配置

☄️ Ideas

配置hostname

优先配置hostname
推荐 orgName-nodeName

hostnamectl set-hostname de-node1

配置hosts

vim /etc/hosts
#172.23.39.242   iZ8vb6he8uo72tekh18ylkZ iZ8vb6he8uo72tekh18ylkZ
172.23.39.242 de-node1

关闭防火墙

systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld

关闭selinux

Note: 防止重启后,自动启动防火墙

vim /etc/selinux/config
SELINUX=disabled
# 查看
getenforce
# 关闭
setenforce 0

创建用户

不推荐密码登录

useradd de
su de
# 一路回撤
ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys

赋予免密sudo权限

vim /etc/sudoers
root    ALL=(ALL)       ALL
de      ALL=(ALL)       NOPASSWD: ALL
检测
ssh de@de-node1
sudo ls /
环境变量重启生效
su de
vim ~/.bashrc
if [ -f /etc/profile ]; then
    source /etc/profile
fi
source ~/.bashrc
挂载磁盘

linux 初始化服务器
https://ispong.isxcode.com/os/linux/linux 初始化服务器/
Author
ispong
Posted on
September 20, 2023
Licensed under