├── image.png ├── ssh-container ├── README.md └── Dockerfile ├── src ├── go.mod ├── go.sum ├── Makefile ├── index.html ├── main.go └── xterm.css ├── Dockerfile ├── .github └── workflows │ └── release.yml ├── LICENSE ├── docker-compose.yml └── README.md /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Razikus/go-ssh-to-websocket/HEAD/image.png -------------------------------------------------------------------------------- /ssh-container/README.md: -------------------------------------------------------------------------------- 1 | # Don't use it 2 | 3 | It exists just for development purposes -------------------------------------------------------------------------------- /src/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Razikus/go-ssh-to-websocket 2 | 3 | go 1.21.1 4 | 5 | require ( 6 | github.com/gorilla/websocket v1.5.1 7 | golang.org/x/crypto v0.22.0 8 | ) 9 | 10 | require ( 11 | golang.org/x/net v0.23.0 // indirect 12 | golang.org/x/sys v0.19.0 // indirect 13 | ) 14 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM golang:1.22.2-alpine3.19 AS builder 3 | COPY src /src 4 | WORKDIR /src 5 | RUN go build -o /sshtows 6 | 7 | FROM scratch 8 | COPY --from=builder /sshtows /sshtows 9 | COPY --from=builder /src/index.html /index.html 10 | COPY --from=builder /src/xterm.js /xterm.js 11 | COPY --from=builder /src/xterm.css /xterm.css 12 | 13 | EXPOSE 8280 14 | ENTRYPOINT [ "/sshtows" ] -------------------------------------------------------------------------------- /ssh-container/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.19 2 | 3 | RUN apk add --no-cache openssh-server 4 | 5 | RUN sed -i 's/#LogLevel INFO/LogLevel VERBOSE/' /etc/ssh/sshd_config 6 | RUN echo 'PermitUserEnvironment yes' >> /etc/ssh/sshd_config 7 | RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config 8 | RUN sed -i 's/#LogLevel INFO/LogLevel VERBOSE/' /etc/ssh/sshd_config 9 | RUN adduser -D admin 10 | RUN echo 'admin:admin123123' | chpasswd 11 | RUN cp /etc/ssh/sshd_config /config 12 | 13 | CMD ssh-keygen -A && /usr/sbin/sshd -f /config -D -e -------------------------------------------------------------------------------- /src/go.sum: -------------------------------------------------------------------------------- 1 | github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= 2 | github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= 3 | golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= 4 | golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= 5 | golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= 6 | golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= 7 | golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= 8 | golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 9 | golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= 10 | golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= 11 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | build: 10 | name: Build and Release 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Check out code 15 | uses: actions/checkout@v2 16 | 17 | - name: Set up Go 18 | uses: actions/setup-go@v2 19 | with: 20 | go-version: 1.22 21 | 22 | - name: Determine Version 23 | id: determine_version 24 | run: echo ::set-output name=VERSION::$(echo "${{ github.ref }}" | sed 's,.*/\(.*\),\1,') 25 | 26 | 27 | - name: Build 28 | run: | 29 | cd src 30 | make all VERSION=${{ steps.determine_version.outputs.VERSION }} 31 | 32 | - name: Create Release 33 | if: startsWith(github.ref, 'refs/tags/') 34 | uses: softprops/action-gh-release@v2 35 | with: 36 | files: | 37 | src/bin/* 38 | env: 39 | GITHUB_TOKEN: ${{ secrets.TOKEN }} 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Adam Raźniewski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '3' 3 | 4 | services: 5 | traefik: 6 | image: traefik:v2.5 7 | command: 8 | - "--log.level=DEBUG" 9 | - "--api.insecure=true" 10 | - "--providers.docker=true" 11 | - "--entrypoints.web.address=:80" 12 | ports: 13 | - "80:80" 14 | volumes: 15 | - "/var/run/docker.sock:/var/run/docker.sock" 16 | labels: 17 | - "traefik.enable=true" 18 | 19 | sshcontainer: 20 | build: 21 | context: ssh-container 22 | 23 | sshtows: 24 | image: docker.io/razikus/sshtows:1.0.1 25 | environment: 26 | SSH_USER: "admin" 27 | SSH_PASS: "admin123123" 28 | SSH_HOST: "sshcontainer" 29 | SSH_PORT: "22" 30 | labels: 31 | - "traefik.enable=true" 32 | - "traefik.http.routers.sshtows-websocket.rule=Path(`/ssh`)" 33 | - "traefik.http.routers.sshtows-websocket.entrypoints=web" 34 | - "traefik.http.routers.sshtows-websocket.middlewares=sshtows-stripprefix" 35 | - "traefik.http.routers.sshtows-static.rule=PathPrefix(`/`)" 36 | - "traefik.http.routers.sshtows-static.entrypoints=web" 37 | - "traefik.http.middlewares.sshtows-stripprefix.stripprefix.prefixes=/ssh" 38 | 39 | - "traefik.http.middlewares.auth.basicauth.users=admin:$$apr1$$ro0zs3dk$$q7CjVX8gtmOrspmhSj5ki0" # admin : admin 40 | - "traefik.http.routers.sshtows-websocket.middlewares=sshtows-stripprefix,auth" 41 | - "traefik.http.routers.sshtows-static.middlewares=auth" 42 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | VERSION=dev 2 | BINARY_NAME=$(VERSION)_ssh2ws 3 | 4 | amd64: 5 | GOOS=linux GOARCH=amd64 go build -o bin/$(BINARY_NAME)_amd64 main.go 6 | 7 | amd64-static: 8 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o bin/$(BINARY_NAME)_amd64_static main.go 9 | 10 | arm32: 11 | GOOS=linux GOARCH=arm go build -o bin/$(BINARY_NAME)_arm32 main.go 12 | 13 | arm32-static: 14 | CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -a -installsuffix cgo -o bin/$(BINARY_NAME)_arm32_static main.go 15 | 16 | arm64: 17 | GOOS=linux GOARCH=arm64 go build -o bin/$(BINARY_NAME)_arm64 main.go 18 | 19 | arm64-static: 20 | CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -installsuffix cgo -o bin/$(BINARY_NAME)_arm64_static main.go 21 | 22 | windows: 23 | GOOS=windows GOARCH=amd64 go build -o bin/$(BINARY_NAME).exe main.go 24 | 25 | windows-static: 26 | CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -installsuffix cgo -o bin/$(BINARY_NAME)_static.exe main.go 27 | 28 | darwin: 29 | GOOS=darwin GOARCH=amd64 go build -o bin/$(BINARY_NAME)_darwin main.go 30 | 31 | darwin-static: 32 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -installsuffix cgo -o bin/$(BINARY_NAME)_darwin_static main.go 33 | 34 | darwinarm64: 35 | GOOS=darwin GOARCH=arm64 go build -o bin/$(BINARY_NAME)_darwinarm64 main.go 36 | 37 | darwinarm64-static: 38 | CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -installsuffix cgo -o bin/$(BINARY_NAME)_darwinarm64_static main.go 39 | 40 | all: amd64 amd64-static arm32 arm32-static arm64 arm64-static windows windows-static darwin darwin-static darwinarm64 darwinarm64-static -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GO SSH TO WEBSOCKET 2 | 3 | This project does exactly what it says 4 | 5 | It's an proxy written in GO that allows to connect to SSH server over WebSocket - just from your browser 6 | 7 | I wrote it for other project, but maybe will be useful for somebody 8 | 9 | 10 |  11 | 12 | 13 | ## Features 14 | 15 | - SSH connection via WebSockets 16 | - Web-based terminal emulation using [xterm.js](https://xtermjs.org/) 17 | - Environment variable configuration for SSH credentials (password based) and settings 18 | - Dockerized 19 | 20 | ## Running in docker 21 | 22 | ``` 23 | 24 | docker run -p 8280:8280 -e SSH_USER=USER -e SSH_PASS=PASS -e SSH_HOST=HOST -e SSH_PORT=PORT --rm docker.io/razikus/sshtows:1.0.1 25 | 26 | ``` 27 | 28 | Go to http://localhost:8280 and you will see terminal 29 | 30 | ## Configuration 31 | 32 | Available env variables 33 | 34 | ``` 35 | SSH_USER="your_username" 36 | SSH_PASS="your_password" 37 | SSH_HOST="ssh.example.com" 38 | SSH_PORT="22" 39 | MOUNT_HTML="true" 40 | ``` 41 | 42 | ## Docker compose with basic auth and simple SSH container 43 | 44 | - 13.05.2024 - just added simple SSH container to make ability to log in inside the system out of the box. 45 | 46 | In docker-compose there is example how to setup basic proxy with basic auth 47 | 48 | In order to change credentials from default (admin : admin) user need to follow traefik tutorial 49 | ``` 50 | https://doc.traefik.io/traefik/middlewares/http/basicauth/ 51 | ``` 52 | 53 | Here you can create htpasswd online (remember to escape $ with $$) 54 | 55 | ``` 56 | https://hostingcanada.org/htpasswd-generator/ 57 | ``` 58 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |