Compare commits
No commits in common. "master" and "v1.0.0-stable" have entirely different histories.
master
...
v1.0.0-sta
@ -1,4 +1,4 @@
|
|||||||
package Tunnel
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AcceptClients(connection net.Listener, config *ssh.ClientConfig, serverAddrString, remoteAddrString string) {
|
func acceptClients(connection net.Listener, config *ssh.ClientConfig) {
|
||||||
|
|
||||||
// Endless loop
|
// Endless loop
|
||||||
for {
|
for {
|
||||||
@ -22,7 +22,7 @@ func AcceptClients(connection net.Listener, config *ssh.ClientConfig, serverAddr
|
|||||||
log.Println(`Client accepted.`)
|
log.Println(`Client accepted.`)
|
||||||
|
|
||||||
// Start the forwarding:
|
// Start the forwarding:
|
||||||
go forward(localConn, config, serverAddrString, remoteAddrString)
|
go forward(localConn, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package Tunnel
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxRetriesLocal = 16 // How many retries are allowed to create the local end-point?
|
maxRetriesLocal = 16 // How many retries are allowed to create the local end-point?
|
@ -1,4 +1,4 @@
|
|||||||
package Tunnel
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateLocalEndPoint(localAddrString string) (localListener net.Listener) {
|
func createLocalEndPoint() (localListener net.Listener) {
|
||||||
|
|
||||||
// Loop for the necessary retries
|
// Loop for the necessary retries
|
||||||
for {
|
for {
|
@ -1,4 +1,4 @@
|
|||||||
package Tunnel
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func forward(localConn net.Conn, config *ssh.ClientConfig, serverAddrString, remoteAddrString string) {
|
func forward(localConn net.Conn, config *ssh.ClientConfig) {
|
||||||
|
|
||||||
defer localConn.Close()
|
defer localConn.Close()
|
||||||
currentRetriesServer := 0
|
currentRetriesServer := 0
|
||||||
@ -17,7 +17,7 @@ func forward(localConn net.Conn, config *ssh.ClientConfig, serverAddrString, rem
|
|||||||
// Loop for retries:
|
// Loop for retries:
|
||||||
for {
|
for {
|
||||||
|
|
||||||
// Try to connect to the SSH server:
|
// Try to connect to the SSD server:
|
||||||
if sshClientConn, err := ssh.Dial(`tcp`, serverAddrString, config); err != nil {
|
if sshClientConn, err := ssh.Dial(`tcp`, serverAddrString, config); err != nil {
|
||||||
|
|
||||||
// Failed:
|
// Failed:
|
@ -1,11 +1,11 @@
|
|||||||
package Tunnel
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Another auth. method.
|
// Another auth. method.
|
||||||
func KeyboardInteractiveChallenge(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
func keyboardInteractiveChallenge(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
||||||
|
|
||||||
// Log all the provided data:
|
// Log all the provided data:
|
||||||
log.Println(`User: ` + user)
|
log.Println(`User: ` + user)
|
||||||
@ -22,7 +22,7 @@ func KeyboardInteractiveChallenge(user, instruction string, questions []string,
|
|||||||
|
|
||||||
// We expect that in this case (only one question is asked), that the server want to know the password ;-)
|
// We expect that in this case (only one question is asked), that the server want to know the password ;-)
|
||||||
answers = make([]string, countQuestions, countQuestions)
|
answers = make([]string, countQuestions, countQuestions)
|
||||||
answers[0] = callbackPassword
|
answers[0] = password
|
||||||
|
|
||||||
} else if countQuestions > 1 {
|
} else if countQuestions > 1 {
|
||||||
|
|
34
Main.go
34
Main.go
@ -1,57 +1,31 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/SommerEngineering/SSHTunnel/Tunnel"
|
|
||||||
"github.com/howeyc/gopass"
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Show the current version:
|
|
||||||
log.Println(`SSHTunnel v1.3.0`)
|
|
||||||
|
|
||||||
// Allow Go to use all CPUs:
|
// Allow Go to use all CPUs:
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
||||||
// Read the configuration from the command-line args:
|
// Read the configuration from the command-line args:
|
||||||
readFlags()
|
readFlags()
|
||||||
|
|
||||||
// Check if the password was provided:
|
|
||||||
for true {
|
|
||||||
if password == `` {
|
|
||||||
// Promt for the password:
|
|
||||||
fmt.Println(`Please provide the password for the connection:`)
|
|
||||||
if pass, errPass := gopass.GetPasswd(); errPass != nil {
|
|
||||||
log.Println(`There was an error reading the password securely: ` + errPass.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
password = string(pass)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the SSH configuration:
|
// Create the SSH configuration:
|
||||||
Tunnel.SetPassword4Callback(password)
|
|
||||||
config := &ssh.ClientConfig{
|
config := &ssh.ClientConfig{
|
||||||
User: username,
|
User: username,
|
||||||
Auth: []ssh.AuthMethod{
|
Auth: []ssh.AuthMethod{
|
||||||
ssh.Password(password),
|
ssh.Password(password),
|
||||||
ssh.PasswordCallback(Tunnel.PasswordCallback),
|
ssh.PasswordCallback(passwordCallback),
|
||||||
ssh.KeyboardInteractive(Tunnel.KeyboardInteractiveChallenge),
|
ssh.KeyboardInteractive(keyboardInteractiveChallenge),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the local end-point:
|
// Create the local end-point:
|
||||||
localListener := Tunnel.CreateLocalEndPoint(localAddrString)
|
localListener := createLocalEndPoint()
|
||||||
|
|
||||||
// Accept client connections (will block forever):
|
// Accept client connections (will block forever):
|
||||||
Tunnel.AcceptClients(localListener, config, serverAddrString, remoteAddrString)
|
acceptClients(localListener, config)
|
||||||
}
|
}
|
||||||
|
6
PasswordCallback.go
Normal file
6
PasswordCallback.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Just a callback function for the password request.
|
||||||
|
func passwordCallback() (string, error) {
|
||||||
|
return password, nil
|
||||||
|
}
|
10
README.md
10
README.md
@ -1,6 +1,6 @@
|
|||||||
SSHTunnel
|
SSHTunnel
|
||||||
=========
|
=========
|
||||||
SSHTunnel is a tiny small program to tunnel something through a SSH without any external dependencies. Just download the executable which matches your OS and architecture (32 vs. 64 bits) and run it.
|
SSHTunnel is a tiny small program to tunnel something through a SSH without any external dependencies. Yes, you do not need any PuTTY installtion for Microsoft Windows. Just download the executable which matches your OS and architecture (32 vs. 64 bits) and run it.
|
||||||
|
|
||||||
### Syntax
|
### Syntax
|
||||||
*This example uses the Microsoft Windows executable, but the syntax is the same for e.g. Linux, Unix, Mac, etc.*
|
*This example uses the Microsoft Windows executable, but the syntax is the same for e.g. Linux, Unix, Mac, etc.*
|
||||||
@ -10,21 +10,19 @@ SSHTunnel is a tiny small program to tunnel something through a SSH without any
|
|||||||
- At the SSH server's side, connects to `127.0.0.1` to port `27017` (a MongoDB database)
|
- At the SSH server's side, connects to `127.0.0.1` to port `27017` (a MongoDB database)
|
||||||
- At your local side, provides a listener at `127.0.0.1` at the port `53001`
|
- At your local side, provides a listener at `127.0.0.1` at the port `53001`
|
||||||
- The username for the SSH service is `john`
|
- The username for the SSH service is `john`
|
||||||
- The user's password would be `johndow` ;-) You can avoid the `-pwd` argument. Thus, the SSHTunnel will ask for the password.
|
- The user's password would be `johndow` ;-)
|
||||||
- Now, you are able to use your local MongoDB software and can connect to port `53001` at `localhost`.
|
- Now, you are able to use your local MongoDB software and can connect to port `53001` at `localhost`.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
- The whole code is open source and can be used for any purpose (also commercial)
|
- The whole code is open source and can be used for any purpose (also commercial)
|
||||||
- If you want, you can compile the code by your own by using the [Go](http://www.golang.org)
|
- If you want, you can compile the code by your own by using the Go compiler (http://www.golang.org)
|
||||||
- The program just needs very low resources e.g. around 1.3 MB memory for Microsoft Windows 8.1
|
- The program just needs very low resources e.g. around 1.3 MB memory for Microsoft Windows 8.1
|
||||||
- SSHTunnel is scalable and, if necessary, can utilise all your CPUs
|
- SSHTunnel is scalable and, if necessary, can utilise all your CPUs
|
||||||
- If a connection cannot setup, the program re-tries it
|
- If a connection cannot setup, the program re-tries it
|
||||||
- At the moment, SSHTunnel uses only the password authentication methods. Therefore, it is currently not possible to use e.g. a certificate, etc. Nevertheless, the implementation of this feature is possible.
|
- At the moment, SSHTunnel uses only the password authentication methods. Therefore, it is currently not possible to use e.g. a certificate, etc. Nevertheless, the implementation of this feature is possible.
|
||||||
- The configuration must be provided by using the command-line arguments. It is currently not possible to use e.g. a configuration file.
|
- The configuration must be provided by using the command-line arguments. It is currently not possible to use e.g. a configuration file.
|
||||||
- You can avoid the password argument if you prefer to provide the password on demand.
|
|
||||||
- [Ocean Remote Connections](https://github.com/SommerEngineering/OceanRemoteConnections) is a simple GUI for SSH Tunnel, PuTTY, RDP and WinSCP.
|
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
Go and get the latest release from the [release page](https://github.com/SommerEngineering/SSHTunnel/releases).
|
Go and get the latest release from GitHub's release page: https://github.com/SommerEngineering/SSHTunnel/releases
|
||||||
|
|
||||||
*Based on damick's example code from http://stackoverflow.com/questions/21417223/simple-ssh-port-forward-in-golang*
|
*Based on damick's example code from http://stackoverflow.com/questions/21417223/simple-ssh-port-forward-in-golang*
|
||||||
|
@ -8,7 +8,7 @@ func readFlags() {
|
|||||||
flag.StringVar(&serverAddrString, `server`, `127.0.0.1:22`, `The (remote) SSH server, e.g. 'my.host.com', 'my.host.com:22', '127.0.0.1:22', 'localhost:22'.`)
|
flag.StringVar(&serverAddrString, `server`, `127.0.0.1:22`, `The (remote) SSH server, e.g. 'my.host.com', 'my.host.com:22', '127.0.0.1:22', 'localhost:22'.`)
|
||||||
flag.StringVar(&localAddrString, `local`, `127.0.0.1:50000`, `The local end-point of the tunnel, e.g. '127.0.0.1:50000', 'localhost:50000'.`)
|
flag.StringVar(&localAddrString, `local`, `127.0.0.1:50000`, `The local end-point of the tunnel, e.g. '127.0.0.1:50000', 'localhost:50000'.`)
|
||||||
flag.StringVar(&remoteAddrString, `remote`, `127.0.0.1:27017`, `The remote side end-point (e.g. on the machine with the SSH server), e.g. a MongoDB (port 27017) '127.0.0.1:27017', a web server '127.0.0.1:80'`)
|
flag.StringVar(&remoteAddrString, `remote`, `127.0.0.1:27017`, `The remote side end-point (e.g. on the machine with the SSH server), e.g. a MongoDB (port 27017) '127.0.0.1:27017', a web server '127.0.0.1:80'`)
|
||||||
flag.StringVar(&username, `user`, `username`, `The user's name for the SSH server.`)
|
flag.StringVar(&username, `user`, `username`, `The user's name for the SSD server.`)
|
||||||
flag.StringVar(&password, `pwd`, ``, `The user's password for the SSH server.`)
|
flag.StringVar(&password, `pwd`, `password`, `The user's password for the SSD server.`)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package Tunnel
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
@ -1,10 +0,0 @@
|
|||||||
package Tunnel
|
|
||||||
|
|
||||||
// Just a callback function for the password request.
|
|
||||||
func PasswordCallback() (string, error) {
|
|
||||||
return callbackPassword, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetPassword4Callback(password string) {
|
|
||||||
callbackPassword = password
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package Tunnel
|
|
||||||
|
|
||||||
var (
|
|
||||||
currentRetriesLocal = 0 // Check how many retries are occur for creating the local end-point
|
|
||||||
callbackPassword = ``
|
|
||||||
)
|
|
11
Variables.go
11
Variables.go
@ -1,9 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var (
|
var (
|
||||||
username = `` // The SSH user's name
|
username = `` // The SSH user's name
|
||||||
password = `` // The user's password
|
password = `` // The user's password
|
||||||
serverAddrString = `` // The SSH server address
|
serverAddrString = `` // The SSH server address
|
||||||
localAddrString = `` // The local end-point
|
localAddrString = `` // The local end-point
|
||||||
remoteAddrString = `` // The remote end-point (on the SSH server's side)
|
remoteAddrString = `` // The remote end-point (on the SSH server's side)
|
||||||
|
currentRetriesLocal = 0 // Check how many retries are occur for creating the local end-point
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user