概要
鍵を作成し登録してあげます
環境
- macOS 15.7.1
- docker 29.1.2
- linuxserver/openssh-server 10.0_p1-r10-ls211
compose.yaml
services:
ssh_server:
image: ghcr.io/linuxserver/openssh-server
container_name: ssh_server
ports:
- "2222:2222"
- "10022:10022" # SSHリモートポートフォーワードトンネル用
environment:
- PUID=1000
- PGID=1000
- PASSWORD_ACCESS=false
- USER_NAME=operator
- PUBLIC_KEY_FILE=/config/ssh/authorized_keys
volumes:
- ./custom-cont-init.d:/custom-cont-init.d:ro
- ./config/ssh:/config/ssh
restart: unless-stopped
custom-cont-init.d/01-sshd-config.sh
#!/bin/bash
echo "[custom-init] modifying sshd_config..."
# 対象ファイル
SSHD_CONFIG="/config/sshd/sshd_config"
# Agent Forwarding
sed -i 's/#AllowAgentForwarding yes/AllowAgentForwarding yes/' "$SSHD_CONFIG"
# TCP Forwarding
sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/' "$SSHD_CONFIG"
# GatewayPorts
sed -i 's/GatewayPorts no/GatewayPorts yes/' "$SSHD_CONFIG"
# X11Forwarding──
sed -i 's/X11Forwarding no/X11Forwarding yes/' "$SSHD_CONFIG"
echo "[custom-init] done."
- chmod +x config/custom-cont-init.d/01-sshd-config.sh
鍵作成
-
ssh-keygen -t ed25519 -f operator_key
-
mkdir -p config/ssh
-
mv operator_key.pub config/ssh/authorized_keys
動作確認
- docker compose up -d
-
chmod 600 operator_key
-
ssh -i operator_key operator@localhost -p 2222
ホストの警告が出る場合は以下で無視しましょう
-
ssh -i operator_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null operator@localhost -p 2222
リモートSSHトンネルは以下
-
ssh -i operator_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -N -R 10022:localhost:22 operator@192.168.1.100 -p 2222
最後に
ログインしたいサーバに鍵を渡しましょう
0 件のコメント:
コメントを投稿