2023-07-22 22:02:33 +08:00
|
|
|
|
#cloud-config
|
2023-11-12 17:29:15 +08:00
|
|
|
|
datasource_list: [None]
|
2023-08-07 23:28:02 +08:00
|
|
|
|
timezone: Asia/Shanghai
|
2023-07-22 22:02:33 +08:00
|
|
|
|
disable_root: false
|
|
|
|
|
ssh_pwauth: true
|
|
|
|
|
users:
|
|
|
|
|
- name: root
|
|
|
|
|
lock_passwd: false
|
|
|
|
|
chpasswd:
|
|
|
|
|
expire: false
|
2024-10-13 22:58:12 +08:00
|
|
|
|
# <= cloud-init 22.2.x 需要
|
2023-07-22 22:02:33 +08:00
|
|
|
|
list: |
|
2024-05-22 21:56:11 +08:00
|
|
|
|
root:@PASSWORD@
|
2023-07-22 22:02:33 +08:00
|
|
|
|
users:
|
|
|
|
|
- name: root
|
2024-05-22 21:56:11 +08:00
|
|
|
|
password: "@PASSWORD@"
|
2024-10-13 22:58:12 +08:00
|
|
|
|
type: hash
|
2023-07-22 22:02:33 +08:00
|
|
|
|
runcmd:
|
2024-05-03 23:34:42 +08:00
|
|
|
|
# opensuse tumbleweed 镜像有 /etc/ssh/sshd_config.d/ 文件夹,没有 /etc/ssh/sshd_config,有/usr/etc/ssh/sshd_config
|
|
|
|
|
# opensuse tumbleweed cloud-init 直接创建并写入 /etc/ssh/sshd_config,造成默认配置丢失
|
|
|
|
|
# 下面这行删除 clout-init 创建的 sshd_config
|
|
|
|
|
- test $(wc -l </etc/ssh/sshd_config) -le 1 && cat /etc/ssh/sshd_config >>/etc/ssh/sshd_config.d/50-cloud-init.conf && rm -f /etc/ssh/sshd_config
|
2024-11-29 22:13:53 +08:00
|
|
|
|
- echo "PermitRootLogin yes" >/etc/ssh/sshd_config.d/01-permitrootlogin.conf 2>/dev/null || sed -Ei 's/^#?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
2024-10-12 23:07:01 +08:00
|
|
|
|
- echo "Port @SSH_PORT@" >/etc/ssh/sshd_config.d/01-change-ssh-port.conf || sed -Ei 's/^#?Port .*/Port @SSH_PORT@/' /etc/ssh/sshd_config
|
2024-05-22 21:48:17 +08:00
|
|
|
|
# 已创建的 ssh 连接会沿用旧的配置(未开启密码登录),这时即使输入正确的密码,也会提示 Access Denied
|
|
|
|
|
# systemctl restart sshd 只会重启监听进程,不会关闭已创建的连接(子进程)
|
|
|
|
|
- pkill sshd || true
|
2024-10-12 23:07:01 +08:00
|
|
|
|
# daemon-reload 会刷新 /run/systemd/generator/ssh.socket.d/addresses.conf
|
|
|
|
|
- systemctl daemon-reload
|
2024-11-29 22:13:53 +08:00
|
|
|
|
- for s in ssh.socket ssh.service sshd.socket sshd.service; do systemctl is-enabled $s 2>/dev/null && systemctl restart $s && break; done
|
2024-10-13 22:58:12 +08:00
|
|
|
|
# 删除有密码的行
|
2024-10-12 23:07:01 +08:00
|
|
|
|
- sed -i -e '/^[[:space:]]*password:/d' -e '/[[:space:]]*root:/d' /etc/cloud/cloud.cfg.d/99_fallback.cfg
|
2023-09-10 22:23:05 +08:00
|
|
|
|
- touch /etc/cloud/cloud-init.disabled
|
2023-10-22 00:46:53 +08:00
|
|
|
|
# ubuntu 镜像运行 echo -e '\nDone' ,-e 会被显示出来
|
2024-10-18 23:58:04 +08:00
|
|
|
|
# 加 true 因为有的 tty 不可写
|
|
|
|
|
- for tty in tty0 ttyS0 ttyAMA0; do [ -c /dev/$tty ] && printf '\n%s\n' 'reinstall done' >/dev/$tty || true; done
|