https://github.com/europ/docker-centos-sshd-systemd
Docker image for CentOS including SSHD and SystemD.
https://github.com/europ/docker-centos-sshd-systemd
centos docker dockerhub ssh sshd systemd
Last synced: 5 months ago
JSON representation
Docker image for CentOS including SSHD and SystemD.
- Host: GitHub
- URL: https://github.com/europ/docker-centos-sshd-systemd
- Owner: europ
- License: mit
- Created: 2020-09-10T06:21:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-29T10:42:46.000Z (about 5 years ago)
- Last Synced: 2025-05-15T14:11:47.209Z (5 months ago)
- Topics: centos, docker, dockerhub, ssh, sshd, systemd
- Language: Dockerfile
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://hub.docker.com/r/europ/docker-centos-sshd-systemd/builds)
# docker-centos-sshd-systemd
Docker image for CentOS including SSHD and SystemD.
## Specifications
##### OS
* SSHD
* systemd##### Users
* username=`root`, password=`root`
* username=`user`, password=`user`
* passwordless sudo user
* owns SSH key##### SSHD
* root login is not permitted
* password authentification is not permitted
* user authentification is passwordless via SSH key
* ssh public key `./secret/ssh/sshkey.pub` is imported into container##### SSH-key
* passphrase is unset
* owned by user## Usage - from dockerhub
##### Quick run
```sh
# pull
docker pull europ/docker-centos-sshd-systemd# run
docker run --tty --detach --privileged --publish 22:22 --label="xyz" -v /sys/fs/cgroup:/sys/fs/cgroup:ro europ/docker-centos-sshd-systemd# add your custom ssh key
docker cp /path/to/your/sshkey.PUBLIC :/home/user/.ssh/authorized_keys# test
ssh -i /path/to/your/sshkey.PRIVATE user@ '[ "`ps --no-headers -p 1 -o comm`" == "systemd" ]'
```##### Customization
* it is important to add `CMD ["/usr/sbin/init"]` command as the last one
```sh
FROM europ/docker-centos-sshd-systemd# EXAMPLE
RUN yum -y install httpd
RUN systemctl enable httpd.service
EXPOSE 80# it is important to include the below command as the last one
CMD ["/usr/sbin/init"]
```## Usage - from scratch
##### Build
```sh
docker build --rm --tag=abc --label="xyz" .
```##### Run
* note the important **`--privileged`** parameter
* add additional `--publish :` if needed```sh
docker run --tty --detach --privileged --publish 22:22 --label="xyz" -v /sys/fs/cgroup:/sys/fs/cgroup:ro abc
```##### Work
```sh
# get container ID
CONTAINER_ID=$(docker ps --quiet --all --filter "status=running" --filter "label=xyz")# get container IP
CONTAINER_IP=$(docker inspect ${CONTAINER_ID} | grep -E '^\s*"IPAddress": ".*$' | grep -ohE "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | head -1)# connect to the running container
ssh -i ./secret/ssh/sshkey user@${CONTAINER_IP}
```##### Stop
```sh
docker stop `docker ps --quiet --all --filter "status=running" --filter "label=xyz"`
```## FAQ
##### Warning: Remote host identification has changed
* warning output:
```txt
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:xxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxx/xxxxxxxxx.
Please contact your system administrator.
Add correct host key in /home/${USER}/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/${USER}/.ssh/known_hosts:2
remove with:
ssh-keygen -f "/home/${USER}/.ssh/known_hosts" -R "172.17.0.2"
ECDSA host key for 172.17.0.2 has changed and you have requested strict checking.
Host key verification failed.
```* solution:
```sh
ssh-keygen -f "/home/${USER}/.ssh/known_hosts" -R ""
```##### How to change the placeholding SSH keys?
* method: one docker command
1. copy the ssh public key to container via `docker cp /path/to/your/sshkey.pub :/home/user/.ssh/authorized_keys`
* method: new image build
1. clone this repository
1. change the ssh key files in `./secret/ssh/sshkey`
1. build it (follow the usage instruction from [*Build* section](#build))## Further Reading
Container problem relater to systemd:
*
CentOS7 container including only systemd:
*
How to run systemd in a container:
*
Dockerize an SSH service:
*
## Contribution
Feel free to open an [issue](https://github.com/europ/docker-centos-sshd-systemd/issues) or a [change request](https://github.com/europ/docker-centos-sshd-systemd/pulls) in this repository in case of a bug, problem, request for enhancement, feature idea, suggestion, etc.