Created
April 15, 2025 10:19
-
-
Save PrintNow/13944b9b744bfd18234c61a9db0e3f67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 更新 APK 包索引 | |
apk update | |
# 安装 OpenSSH 服务 | |
apk add openssh | |
# 生成 SSH 主机密钥 | |
ssh-keygen -A | |
# 创建 SSH 服务所需的目录和文件 | |
mkdir -p /root/.ssh | |
chmod 700 /root/.ssh | |
# 将证书内容添加到 authorized_keys 文件中 | |
# 你可以后续将实际的公钥内容替换掉下面的注释部分 | |
cat << EOF > /root/.ssh/authorized_keys | |
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA9AySUSUzO+dWXMkPLb/7tXcQW5RQxf/fqoMEMsJFx0ksoQ6CkBWBpH59bZNbiCXaHZozLff2r1w/N4aH1p5SSf4c21Trry0lrOnjMfSmPRUCifGYFQ8ytCZejjOLigc00oLec0ec/14EzouUWOKaRxaZV5TtDLEk4SvHP3osSSEM5VXo65pYztrnsSIf3OplqN1N664ypGnCay5u+kXqQkVZ0R7fS7Yg3bAZ6uGec72qVdATiJVfN7PmoWy0FsY+91K/IRlpg5mdznKEroGGUfBMfFvF/FEM8E0Q6OM1TUeQ2IX0iKS1DVUyOzY14LphGRT3PypbomWS3f2VXEsHNw== | |
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM4GrcXzGici4VjRFiK3BYQkRQt528LPsdgtKYHAEz7J | |
EOF | |
chmod 600 /root/.ssh/authorized_keys | |
# 配置 SSHD 服务允许 root 用户登录 | |
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config | |
# 启动 SSHD 服务并使其在后台运行 | |
/usr/sbin/sshd | |
# 获取并打印容器的 IP 地址 | |
CONTAINER_IP=$(hostname -i) | |
echo "Container IP: $CONTAINER_IP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment