How to run an SSH server in Docker and on the host machine on the same port?
I want to run a Git server in Docker, and have a regular SSH server on the host, with both sharing the same port.
The Git server uses git@ip while the SSH server uses user@ip.
Is it possible to bounce packets sent to git@ip to the Docker container, or something, such that I can connect to either server without changing the port?
Top Answer/Comment:
An alternative would be to run the git server on a different port and then use the ~/.ssh/config file to map a different hostname/user to the other port
e.g.
Host docker.example.com
User ubuntu
Port 22
Hostname docker.example.com
Host git.docker.example.com
User git
Port 2222
Hostname docker.example.com
The Hostname docker.exmaple.com can be a IP address.
Add this to the client machine would mean that ssh [email protected] would connect to the default port 22 but ssh [email protected] will connect to port 2222.
You will need to add the config file to all the machines you want to connect from.
Second option (speculation) you may be able to swap the shell for the git user to a shell script that runs ssh localhost -p 2222 (having mapped port 2222 to localhost for the git container.
I think this could work, but would need to remember to add the /etc/shells file.
상단 광고의 [X] 버튼을 누르면 내용이 보입니다