Linux

Commands

hostnamectl

1
hostnamectl set-hostname newname #改主机名(永久修改,下次登录生效)

timedatectl

1
2
timedatectl set-timezone Asia/Shanghai #修改时区
timedatectl set-ntp true #启用网络时间同步

Services

SSH

Path:/etc/ssh/sshd_config

基本设置

1
2
3
4
5
6
7
8
Port 22 #监听端口
LoginGraceTime 1m #登录时间限制 2m(2分钟)
PermitRootLogin yes #允许Root登录
#StrictModes yes
MaxAuthTries 3 #最大尝试次数
#MaxSessions 10 #最大会话数
AllowUsers ling #登录白名单(启用白名单,root不加也登录不了)
DenyUsers ling #登录黑名单

密钥登录

1
2
#PubkeyAuthentication yes #启用密钥验证
#PasswordAuthentication yes #启用密码验证
1
ssh-keygen #创建密钥

Path:/user/.ssh

1
2
id_rsa #私钥
id_rsa.pub #公钥

Path:/user/.ssh/authorized_keys

存放远程主机的公钥(方便远程用户登录,不需要传送私钥)

1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCjQn77P1x77rHEDW6Ntmh5L0A+dA6Vyc9VdU5RQ8ZX+8oBe+XAhG7a1VsTxeKi1ophUE/SHOxtVUxiLVmA0x9nSk9B1fRsTAQgrWaOT7MgS+XoUWRlhfdGDQ2Hxd4r/j8KtA2zLLZsJtj7mfLTzZNHAjXoCkU+vj+cfpX5nT9olyPDihQfP/Ytp2JUN/MBDOpVUQcVi85f4ksp0VEuT3f7th9n+vtzVCoNvDyKYErOBWmmwU+5LdZv2K83uOn1R8AFCKBgJSnbfkCkCYYjnGy49g+SsBDofQs++2KgEQbns8b2CXFs54wp7s/L6xWA5T7OA/SbpwWDq/TIPJ1XFIjtcI9DGQw6bAAjGDs6w3yVYiQ263l7w87e3JZIpdaHzECkKdLgLO5BW5kqnC+tQb0dIqclpGHJvO2Y+22VKyyQPQKiPsIa+yEiY0cQHQ3wW5gwJteOHHQtD1Lwq2HOoURuRqWKQZG2N4sYaJheh1kzC/mlSpxTfX0gpHs2mrVAQP0= [email protected]

通过ssh复制公钥到服务器的root用户的authorized_keys

1
ssh-copy-id [email protected]

Debian

Network

Path:/etc/network/interfaces

1
2
3
4
5
auto ens33
iface ens33 inet static
address 192.168.1.27
netmask 255.255.255.0
gateway 192.168.1.100

Reload

1
systemctl restart networking.service

Dns

Path:/etc/resolv.conf

1
2
nameserver 223.5.5.5
nameserver 119.29.29.29

Software

Mirror

Network Mirror

Path:/etc/apt/sources.list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#USTC 
deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free

#tuna
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

Loacal mirror

1
2
3
#挂载CDROM
mkdir /mnt/debian_mirror
mount /dev/cdrom /mnt/debian_mirror/

Path:/etc/apt/sources.list

1
2
#Local mirror
deb [trusted=yes] file:/mnt/debian_mirror bullseye contrib main # Debian 11(Bullseye)

Debina版本代号

1
2
3
Debian 10.0 (buster)
Debian 11.0 (bullseye)
Debian 12.0 (bookworm)

Command

1
2
3
4
5
6
7
8
9
apt-get install  # 安装新包
apt-get remove # 卸载已安装的包(保留配置文件)
apt-get purge # 卸载已安装的包(删除配置文件)
apt-get update # 更新软件包列表
apt-get upgrade # 更新所有已安装的包
apt-get autoremove # 卸载已不需要的包依赖
apt-get dist-upgrade # 自动处理依赖包升级
apt-get autoclean # 将已经删除了的软件包的.deb安装文件从硬盘中删除掉
apt-get clean # 删除软件包的安装包

Centos

Network

Path:/etc/sysconfig/network-scripts/ifcfg-ens33

1
2
3
4
5
6
7
8
DEVICE=eth0                   # 物理设备名
IPADDR=192.168.1.10 # IP地址
NETMASK=255.255.255.0 # 掩码值
NETWORK=192.168.1.0 # 网络地址 ( 可不要 )
BROADCAST=192.168.1.255 # 广播地址( 可不要 )
GATEWAY=192.168.1.1 # 网关地址
ONBOOT=yes # [yes|no](引导时是否激活设备)--开机自启
BOOTPROTO=static # [none|static|bootp|dhcp](引导时不使用协议|静态分配|BOOTP协议|DHCP协议)

Reload

1
systemctl restart network.service

DNS

Path:/etc/resolv.conf

1
2
nameserver 223.5.5.5
nameserver 119.29.29.29

Arch