Skip to content

Commit

Permalink
added support for the user@host notation
Browse files Browse the repository at this point in the history
  • Loading branch information
kt97679 committed Apr 12, 2022
1 parent 32e92a9 commit f234650
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Usage: ossh [-?AinPv] [-c COMMAND] [-C COMMAND_FILE] [-H HOST_STRING] [-h HOST_F
$
```

HOST\_STRING can specify non standard port e.g. ```host.com:2222```.
HOST\_STRING can specify non standard port and different user name e.g. ```user@host.com:2222```.
HOST\_FILE can use #-style comments.
Brace expansion can be used. E.g. "host{1,3..5}.com" would expand to "host1.com host3.com host4.com host5.com"

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220325170049-de3da57026de h1:pZB1TWnKi+o4bENlbzAgLrEbY4RMYmUIRobMcSmfeYc=
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
Expand Down
8 changes: 8 additions & 0 deletions ossh_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type OsshHost struct {
address string
label string
port int
user string
err error
exitStatus int
sshc *ssh.Client
Expand Down Expand Up @@ -118,6 +119,13 @@ func (host *OsshHost) setSSHClient(config *ssh.ClientConfig, socks5ProxyAddr str
}
}
timeoutConn := &Conn{conn, host}
if host.user != "" {
config = &ssh.ClientConfig{
User: host.user,
Auth: config.Auth,
HostKeyCallback: config.HostKeyCallback,
}
}
clientConn, chans, reqs, err := ssh.NewClientConn(timeoutConn, addr, config)
if err != nil {
conn.Close()
Expand Down
7 changes: 7 additions & 0 deletions ossh_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,17 @@ func (s *OsshSettings) getHost(address string, label string) (*OsshHost, error)
return nil, err
}
}
hostUser := ""
userAndAddress := strings.Split(hostAddress, "@")
if len(userAndAddress) > 1 {
hostUser = userAndAddress[0]
hostAddress = userAndAddress[1]
}
host := OsshHost{
address: hostAddress,
label: label,
port: hostPort,
user: hostUser,
err: nil,
connectTimeout: time.Duration(*(s.connectTimeout)) * time.Second,
runTimeout: time.Duration(*(s.runTimeout)) * time.Second,
Expand Down

0 comments on commit f234650

Please sign in to comment.