Created
September 27, 2025 15:17
-
-
Save suenot/46ffd9ff40b363829468dea86d4a51db to your computer and use it in GitHub Desktop.
ubuntu in docker with sshd
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
| # SSH_KEY=$(cat ~/.ssh/id_ed25519.pub) docker compose up -d | |
| version: '3.8' | |
| services: | |
| ubuntu-ssh: | |
| image: ubuntu:22.04 | |
| container_name: ubuntu-ssh | |
| hostname: ubuntu-ssh | |
| environment: | |
| - SSH_KEY=${SSH_KEY} | |
| ports: | |
| - "2222:22" | |
| command: > | |
| bash -c " | |
| apt-get update && | |
| apt-get install -y openssh-server && | |
| mkdir -p /run/sshd && | |
| mkdir -p /root/.ssh && | |
| chmod 700 /root/.ssh && | |
| echo \"$$SSH_KEY\" > /root/.ssh/authorized_keys && | |
| chmod 600 /root/.ssh/authorized_keys && | |
| sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config && | |
| sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config && | |
| /usr/sbin/sshd -D | |
| " | |
| restart: unless-stopped | |
| stdin_open: true | |
| tty: true |
Author
Author
docker exec -it ubuntu-suenot bash
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
snap install docker
2025-09-29T15:35:01+02:00 INFO Waiting for automatic snapd restart...
docker 28.1.1+1 from Canonical✓ installed
docker compose -f docker-compose.yml up -d