Alpine Linux 原始安装的是 busybox,小巧精干,但毕竟与主流的 Bash 还是有区别,特别是与其它系统联动时会比较麻烦,所以还是安装 Bash,统一 Shell 环境,方便日后使用。
而且基本网上的安装教程都有问题,所以这里给出正确的安装步骤。
$ apk add bash libuser
$ touch /etc/login.defs
$ mkdir /etc/default
$ touch /etc/default/useradd
$ lchsh <root>
Changing shell for root.
Password: <root password>
New Shell [/bin/ash]: /bin/bash
Shell changed.
apt install -y systemd-timesyncd
# 设置时区
timedatectl set-timezone Asia/Shanghai
# 启动NTP服务
timedatectl set-ntp true
; /etc/systemd/timesyncd.conf
[Time]
NTP=ntp.ntsc.ac.cn
FallbackNTP=ntp.aliyun.com ntp.tencent.com 0.cn.pool.ntp.org
# 在LXC、Docker 或某些 VPS 环境中
dpkg-reconfigure tzdata
systemctl stop 'postfix@*' ; systemctl disable 'postfix@\x2a' ; apt purge -y postfix
apt install -y wpa_supplicant
; /etc/wpa_supplicant/wlp2s0.conf
p2p_disabled=1
network={
ssid="<ssid>"
psk="<pwd>"
}
# 测试配置文件
wpa_supplicant -c /etc/wpa_supplicant/wlp2s0.conf -i wlp2s0 -B
# 重启wpa_supplicant服务
systemctl enable wpa_supplicant
systemctl start wpa_supplicant
# 编辑wpa_supplicant服务
systemctl edit wpa_supplicant
### Editing /etc/systemd/system/wpa_supplicant.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file
[Service]
ExecStart=
ExecStart=/usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wlp2s0.conf -i wlp2s0
Type=simple
Restart=on-failure
RestartSec=5
TimeoutStartSec=180
### Edits below this comment will be discarded
......
systemctl daemon-reload
systemctl restart wpa_supplicant
# 创建服务
tee /etc/systemd/system/wifi-powersave.service << 'EOF'
[Unit]
Description=Disable WiFi Power Saving
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/iwconfig wlp2s0 power off
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
# 启动服务
systemctl enable wifi-powersave.service
systemctl start wifi-powersave.service
apt install -y systemd-networkd systemd-resolved
; 此处参考/etc/network/interfaces文件里的配置
; /etc/systemd/network/10-lo.network
[Match]
Name=lo
[Network]
# 启用链路本地地址(IPv4 和 IPv6)
LinkLocalAddressing=yes
IPv6LinkLocalAddressGenerationMode=stable-privacy
[Address]
Address=127.0.0.1/8
[Address]
Address=::1/128
; 此处参考/etc/network/interfaces文件里的配置
; 无线网卡
; /etc/systemd/network/20-wireless.network
[Match]
Name=wlp2s0
[Network]
Address=192.168.1.94/24
Gateway=192.168.1.1
DNS=192.168.1.6
; 禁用IPv6
LinkLocalAddressing=no
IPv6AcceptRA=no
# 重启systemd-networkd服务
systemctl enable systemd-networkd
systemctl start systemd-networkd
# 编辑systemd-networkd服务
systemctl edit systemd-networkd
### Editing /etc/systemd/system/systemd-networkd.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file
[Unit]
After=wpa_supplicant.service
Wants=wpa_supplicant.service
### Edits below this comment will be discarded
......
systemctl daemon-reload
systemctl restart systemd-networkd
systemctl enable --now systemd-resolved
# 将系统的 DNS 配置文件链接到 systemd-resolved 管理的动态文件上,这样它就会自动更新。
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
resolvectl status
systemctl stop networking
systemctl disable networking
apt remove ifupdown
reboot
# 修改命令行提示符
echo "PS1='\[\e[36;40m\][\D{%Y-%m-%d} \A] \[\e[0m\] \[\e[35;40m\]\w\[\e[0m\]\n\[\e[33;40m\][\u@\H]\[\e[0m\] \\$ '" >> ~/.bashrc \
&& . ~/.bashrc
# 打开自定义命令
sed -E -i.bak -e '/(export|eval|alias (ls|ll|l|rm|cp|mv))/s/^# //' ~/.bashrc \
&& . ~/.bashrc
# 允许root密码登录
# 允许密码登录
# 解决SSH自动断开问题
sed -E -i.bak \
-e 's/#(Port 22)/\1/' \
-e 's/#(PermitRootLogin) prohibit-password/\1 yes/' \
-e 's/#(PubkeyAuthentication yes)/\1/' \
-e 's/#(PasswordAuthentication yes)/\1/' \
-e 's/#(AllowTcpForwarding yes)/\1/' \
-e 's/(X11Forwarding yes)/#\1/' \
-e 's/#(Compression delayed)/\1/' \
-e 's/#(ClientAliveInterval) 0/\1 60/' \
-e 's/#(ClientAliveCountMax) 3/\1 3/' \
/etc/ssh/sshd_config \
&& systemctl restart sshd.service