Skip to content

Public key support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
.idea
.ssh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
.idea
.ssh
67 changes: 0 additions & 67 deletions Dockerfile.alpine

This file was deleted.

68 changes: 0 additions & 68 deletions Dockerfile.ubuntu

This file was deleted.

49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Support: amd64, aarch64 (ARM64v8), armhf (ARM32v7), RISC-V (riscv64).

[![Docker Stars](https://img.shields.io/docker/stars/devdotnetorg/openssh-server.svg?maxAge=2592000)](https://github.com/devdotnetorg/docker-openssh-server/) [![Docker pulls](https://img.shields.io/docker/pulls/devdotnetorg/openssh-server.svg)](https://github.com/devdotnetorg/docker-openssh-server/) [![GitHub last commit](https://img.shields.io/github/last-commit/devdotnetorg/docker-openssh-server/master)](https://github.com/devdotnetorg/docker-openssh-server/) [![GitHub Repo stars](https://img.shields.io/github/stars/devdotnetorg/docker-openssh-server)](https://github.com/devdotnetorg/docker-openssh-server/)

Docker official Image Ubuntu, Debian, Alpine with sshd started. Password authentication.
Docker official Image Ubuntu, Debian, Alpine with sshd started. Password or public key authentication.

#### Upstream Links

Expand All @@ -25,9 +25,9 @@ Tags are defined by the mask: `devdotnetorg/openssh-server:<OS_name>-<OS_version

Images for the following OS versions are builded:

* Ubuntu: 16.04, 18.04, 20.04, 22.04, 22.10, 23.04, 23.10, 24.04;
* Ubuntu: 16.04, 18.04, 20.04, 22.04, 23.04, 24.04;
* Debian: 10, 11, 12;
* Alpine: 3.15, 3.16, 3.17, 3.18, 3.19, 3.20.
* Alpine: 3.16, 3.17, 3.18, 3.19, 3.20, 3.21.

### Tags for RISC-V (riscv64)

Expand All @@ -36,20 +36,57 @@ Images for the following OS versions are builded:
* `:alpine-riscv64` - Alpine edge.

## Quick Start


### Private + public key setup

Alternatively to specifying `USER_PASSWORD`, you can set `USER_PUBKEY`. For example:
```sh
# Create SSH keys
printf '.ssh' | tee -a .gitignore .dockerignore >/dev/null
mkdir -- '.ssh'
ssh-keygen -t 'rsa' -b '4096' -C 'sample ssh keys' -f '.ssh/id_rsa'
```

#### Usage of public key in running container

```sh
$ docker run --name openssh-server \
-p 2222:22 \
-e USER_PASSWORD='null' \
-e USER_PUBKEY="$(cat -- .ssh/id_rsa.pub)" \
devdotnetorg/openssh-server:ubuntu
```

### Environment Variables

Set variable of password for root user:

`-e USER_PASSWORD=123456`

Or alternatively specify `-e USER_PUBKEY` as per above.

Run container with public port for connections is `2222`, password for user root is `654321`, volume `openssh-server-data` for transfer data in/out of container:

`$ docker run -d --name openssh-server -p 2222:22 -e USER_PASSWORD=654321 -v openssh-server-data:/data devdotnetorg/openssh-server:ubuntu`
```sh
$ docker run -d --name openssh-server \
-p 2222:22 \
-e USER_PASSWORD=654321 \
-v openssh-server-data:/data \
devdotnetorg/openssh-server:ubuntu
````


For network is mynetwork:

`$ docker run -d --name openssh-server --net mynetwork --ip 172.18.0.20 -p 2222:22 -e USER_PASSWORD=654321 -v openssh-server-data:/data devdotnetorg/openssh-server:ubuntu`
```sh
$ docker run -d --name openssh-server \
--net mynetwork \
--ip 172.18.0.20 \
-p 2222:22 \
-e USER_PASSWORD=654321 \
-v openssh-server-data:/data \
devdotnetorg/openssh-server:ubuntu
```

docker-compose:

Expand Down
68 changes: 68 additions & 0 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
###########################################
# Official Image Alpine with OpenSSH server
# Allow SSH connection to the container
# Installed: openssh-server, mc, htop, zip,
# tar, iotop, ncdu, nano, vim, bash, sudo
# for net: ping, traceroute, telnet, host,
# nslookup, iperf, nmap, rsync
###########################################

ARG IMAGE_VERSION="alpine:3.20"

FROM $IMAGE_VERSION
# Label docker image
ARG IMAGE_VERSION
LABEL org.devdotnet.docker_openssh_server.maintainers="DevDotNet.Org <[email protected]>"
LABEL maintainer="DevDotNet.Org <[email protected]>"
LABEL build_version="Image version:- ${IMAGE_VERSION}"

# Base
# Set the locale

ENV LANG='en_US.UTF-8'
ENV LANGUAGE='en_US.UTF-8'

# Password for ssh
ENV USER_PASSWORD='123456'
# Pubkey alternative for ssh (set one or the other)
ENV USER_PUBKEY='null'

# Copy to image
COPY copyables /

# Install
RUN <<-EOF
set -eu +f ;
apk update &&
apk add --no-cache --upgrade openssh-server &&
# Utils
apk add --no-cache --upgrade mc htop iotop ncdu tar zip nano vim bash sudo sed &&
# Net utils
apk add --no-cache --upgrade iputils paris-traceroute perl-net-telnet bind-tools iperf nmap rsync
# Deleting keys
rm -rf '/etc/ssh/ssh_host_dsa'* '/etc/ssh/ssh_host_ecdsa'* '/etc/ssh/ssh_host_ed25519'* '/etc/ssh/ssh_host_rsa'* &&
# Config SSH
sed -ri 's|^#PermitRootLogin|PermitRootLogin|' '/etc/ssh/sshd_config' &&
sed -ri 's|^#?PermitRootLogin\s+.*|PermitRootLogin yes|' '/etc/ssh/sshd_config' &&
# Folder Data
mkdir -p '/data' &&
# Cleaning
rm -rf '/var/lib'/{apt,dpkg,cache,log}/ &&
rm -rf '/var/lib/apt/lists'/*.lz4 &&
rm -rf '/var/log'/* &&
rm -rf '/tmp'/* &&
rm -rf '/var/tmp'/* &&
rm -rf '/usr/share/doc/' &&
rm -rf '/usr/share/man/' &&
rm -rf '/var/cache/apk'/* &&
rm -rf "${HOME}"'/.cache' &&
chmod +x '/entrypoint.sh'

EOF

# Port SSH
EXPOSE 22/tcp

ENTRYPOINT ["/entrypoint.sh"]

CMD ["/usr/sbin/sshd", "-D"]
Loading