- SSH container on host
Create a container on HOST Server which will receive the SSH connection from the remote computer
version: '3'
services:
relay_sshforward:
container_name: eec_relay_sshforward
image: docker.io/panubo/sshd
restart: 'always'
expose:
# SSH Port of container: This port needs to be exposed on host = this is the port used by the remote computer to create ssh connection to the container 10001 (host) = 22 (container)
- 10001
# SSH port forwarded to container from remote computer = this is the port of the container where the remote computer will forward its port, for example the SSH port. For example 10002 (host) = 10002 (container) = 22 (remote computer)
- 10002
# NGINX port forwarded to container from remote computer = this is the port of the container where the remote computer will forward its port, for example the NGINX port. For example: 10003 (container) = 80 (remote computer). No need to expose 10003 publicly as the host nginx will forward traffic to this port using vhost. => This is only useful if you want to access the remote computer odoo instance from the internet but using the host as a relay.
- 10003
ports:
- '10001:22'
- '10002:10002'
environment:
# You must provide the a username and ID to allow connection
- SSH_USERS=username:1000:1000
- MOTD="Now logged inside container on host"
volumes:
# You must provide the SSH key used by username to connect to the container without password
- ./volumes/username.pub:/etc/authorized_keys/username:ro
- ./volumes/ssh:/etc/ssh/
networks:
- webproxy
networks:
webproxy:
external:
name: webproxy
-
Open ports/firewall on host
Make sure you open the host port (10001, 10002) so you can connect to it -
Remote computer autossh
On the remote computer, set up a service at boot which will connect to the SSH container on the server (on port 10001), then forward the port 22 of the remote computer to the SSH container on port 10002. This way, you can connect to the remote computer through the HOST using its port 10002.Install autossh on remote computer
sudo apt-get install autosshCreate a file called fwd22.service on the remote computer at ~/
Remark: see the 10002:localhost:22 username@host.com -p 10001 part ? It says, forward teh port 22 of localhost to the port 10002 of the host, to do this, connect to the host by SSH through port 10001 (SSH container SSH port)[Unit] Description=Enable ssh tunnel to remote container, forward port 22 After=network.target [Service] Environment="AUTOSSH_GATETIME=0" ExecStart=/usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -o "ExitOnForwardFailure=Yes" -NR 10002:localhost:22 username@host.com -p 10001 User=xvin3t [Install] WantedBy=multi-user.targetEnable this service and check if it worked
It will show you the log. Make sure no issues. You can check on the logs of the SSH container, the connection should show.sudo cp fwd22.service /etc/systemd/system sudo systemctl enable fwd22.service sudo systemctl start fwd22.service sudo systemctl status fwd22.service====> At this point, you can connect to the remote computer using ssh username@host.com -p 10002 and you will directly be directed to the remote computer.
-
Enable forwarding to Remote computer nginx
This is more advanced and not needed for now. But the idea is the same => it allows you to connect to the remote computer nginx (apps) through the server. Instead of forwarding port 22 of remote computer, we forward port 80.
This part is more complex as you need to manage vhost - to be completed later.Create a file called fwd80.service on the remote computer at ~/
Remark: see the 10003:localhost:80 username@host.com -p 10001 part ? It says, forward teh port 80 of localhost to the port 10003 of the host, to do this, connect to the host by SSH through port 10001 (SSH container SSH port)[Unit] Description=Enable ssh tunnel to remote container, forward port 80 After=network.target [Service] Environment="AUTOSSH_GATETIME=0" ExecStart=/usr/bin/autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -o "ExitOnForwardFailure=Yes" -NR 10003:localhost:80 username@host.com -p 10001 User=xvin3t [Install] WantedBy=multi-user.target Enable this service.sudo cp fwd80.service /etc/systemd/system sudo systemctl enable fwd80.service sudo systemctl start fwd80.service sudo systemctl status fwd80.service- Connect your remote server on your PC at office!
ssh Remote_User@Cloud_Server_IP -p 10002

6338

被折叠的 条评论
为什么被折叠?



