VsCode Remote SSH 默认是不支持 Alpine Linux 的,不过,对 Alpine Linux 进行一些改动,就可以实现,比较方便。
步骤如下:
$ apk del dropbear
$ apk add gcompat libstdc++6 openssh wget git
$ nano /etc/ssh/sshd-config
AllowTcpForwarding yes
PermitTunnel yes
{
"git.path": "/usr/bin/git",
}
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.
WindTerm客户端,取消 “会话设置 -> SSH -> 验证 -> 尝试键盘交互认证” 可已正常连接。
$ apk update
$ apk add openssh-server openssh
; /etc/ssh/sshd_config
# 开放Root登录
- #PermitRootLogin prohibit-password
+ PermitRootLogin yes
# 允许其它用户登录
- #PasswordAuthentication yes
+ PasswordAuthentication yes
# 解决ssh自动断开
- #ClientAliveInterval 0
- #ClientAliveCountMax 3
+ ClientAliveInterval 60
+ ClientAliveCountMax 3
$ rc-service sshd start
$ rc-service sshd restart
# 设置开机启动
$ rc-update add sshd
# 删除开机启动服务
$ rc-update del sshd
# 显示所有服务
# rc-status -a
在 /etc/profile.d 文件夹下,创建sh文件来实现。
在 Alpine 上安装 Docker 真是一件让人感觉非常愉快的事情,因为过程非常简单。
$ nano /etc/apk/repositories
因为 docker 在社区的库里,所以要打开 community 的源。
#/media/cdrom/apks
http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/main
http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/community
#http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main
#http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community
#http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing
$ apk update
$ apk add docker docker-cli-compose
# 这里要特别注意,docker compose 的包名在 Alpine 里是 docker-cli-compose,不是 docker-compose-plugin。
# docker-compose 包是 compose 的独立安装包,官方已经不再支持这种安装方式。
...
$ docker -v
Docker version 20.10.16, build aa7e414fdcb23a66e8fabbef0a560ef1769eace5
$ docker compose version
Docker Compose version v2.12.2
~# nano /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.10.16/24
gateway 192.168.10.10
hostname alpine
# nano /etc/resolv.conf
nameserver 114.114.114.114
~# service networking restart
特点:
不同版本:
Alpine 有许多版本,其中 VIRTUAL 是专门针对虚拟环境优化过的,所以主要使用这个版本来安装。
https://www.alpinelinux.org/downloads/
...
# 使用启动盘启动后,直接使用 root 登录系统
localhost login: root
...
localhost:~# setup-alpine
# 选择键盘布局
# 这里两个都选 cn 或都不选
...
Select keyboard layout: [none] cn
...
Select variant (or 'abort'): cn
# 设置主机名
...
Enter system hostname (fully qualified form, e.g. 'foo.example.org') [localhost] home
# 设置网络
...
Which one do you want to initialize? (or '?' or 'done') [eth0] eth0
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] dhcp
Do you want to do any manual network configuration? (y/n) [n] n
# or 手动输入IP地址
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] 192.168.10.16/24
Gateway? (or 'none') [none] 192.168.10.10
Do you want to do any manual network configuration? (y/n) [n] n
DNS domain name? (e.g 'bar.com')
DNS nameserver(s)? 114.114.114.114
# 设置密码
...
New password:
...
Retype password:
# 设置时区
# PRC 代理中国,也可以输入 Asia/,再输入 Shanghai
...
Which timezone are you in? ('?' for list) [UTC] PRC
# 设备代理
...
HTTP/FTP proxy URL? (e.g. 'http://proxy:8080', or 'none') [none] none
# 设置更新源
# f 是自动测试并选择最快的源,建议使用
...
Enter mirror number (1-74) or URL to add (or r/f/e/done) [1] f
#
Setup a user? (enter a lower-case loginname, or 'no') [no] no
# 设置ssh服务
Which ssh server? ('openssh', 'dropbear', or 'none') [openssh] openssh
# 这里一定要输入 yes
# 许多教程都说 Alpine 默认没有远程登录,都上手动修改,其实是可以在安装时就设备好的
Allow root ssh login? ('?' for help) [prohibit-password] yes
Enter ssh key or URL for root (or 'none') [none] none
# 设置磁盘
...
Which disk(s) would you like to use? (or '?' for help or 'none') [none] sda
...
How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?] sys
...
WARNING: Erase the aboue disk(s) and continue? (y/n) [n] y
...
Installation is complete. Please reboot.
# 到这里安装全部完成
# 准备应答文件
home:~# reboot
home:~# rc-service iptables stop
home:~# rc-update del iptables