Skip to content

Instantly share code, notes, and snippets.

@suenot
Created September 27, 2025 15:17
Show Gist options
  • Select an option

  • Save suenot/46ffd9ff40b363829468dea86d4a51db to your computer and use it in GitHub Desktop.

Select an option

Save suenot/46ffd9ff40b363829468dea86d4a51db to your computer and use it in GitHub Desktop.
ubuntu in docker with sshd
# 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
@suenot
Copy link
Author

suenot commented Sep 29, 2025

version: '3.8'
services:
  ubuntu:
    image: ubuntu:22.04
    container_name: ubuntu-suenot
    hostname: ubuntu-suenot
    command: tail -f /dev/null
    restart: unless-stopped
    stdin_open: true
    tty: true

без sshd

@suenot
Copy link
Author

suenot commented Sep 29, 2025

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

@suenot
Copy link
Author

suenot commented Sep 29, 2025

docker exec -it ubuntu-suenot bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment