Mocked SSH server for development
This is a mocked SSH server built using Ubuntu 22.04 with OpenSSH installed. It's designed to be used in development environments where an SSH server is required.
- Based on Ubuntu 22.04
- OpenSSH Server pre-installed and configured
- Default root user credentials (passwordless):
- Username:
root
- Username:
- Docker installed on your machine
To build the Docker image, navigate to the directory containing this README and run:
docker build --secret id=ssh-key,src=<path-to-your-public-key> -t mock-ssh-server .For example:
docker build --secret id=ssh-key,src=/home/pcolt/.ssh/id_rsa.pub -t mock-ssh-server .After building the image, you can start a container using the following command:
docker run --name ssh-container -p 2222:22 -d mock-ssh-serverThis maps port 22 in the container to port 2222 on your host machine. You can connect to the SSH server using a client by connecting to localhost:2222.
To connect to the running container using an SSH client, use the following command:
ssh root@localhost -p 2222Here are some details about what's configured in this Dockerfile:
- Installs OpenSSH Server (
openssh-server) - Sets up the
/var/run/sshddirectory - Adds a root user with a password of "root"
- Disables password authentication and allows root login:
PermitRootLogin yesPasswordAuthentication no
To customize this Dockerfile:
- Modify the
Dockerfileas needed. - Rebuild the image using
docker build -t mock-ssh-server .. - Run a new container with your changes.
If you need to access files inside the running container, use Docker's file copy command:
docker cp ssh-container:/etc/ssh/sshd_config ./local_sshd_configThis will copy the sshd_config file from the container to your local machine.
To execute commands inside the running container, use:
docker exec -it ssh-container /bin/bashThis opens a bash shell in the container, allowing you to run commands as if you were logged in directly.