Skip to content

Commit

Permalink
Stop hardcoding the default port for ssh
Browse files Browse the repository at this point in the history
In case the Port is given in the ssh config already...

The ssh command will know the default port, otherwise.

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Dec 30, 2021
1 parent 611af10 commit b89aa7e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/sshocker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
func parseHost(s string) (string, int, error) {
if !strings.Contains(s, ":") {
// FIXME: this check is not valid for IPv6!
return s, 22, nil
return s, 0, nil
}
host, portStr, err := net.SplitHostPort(s)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions pkg/reversesshfs/reversesshfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func (rsf *ReverseSSHFS) Prepare() error {
if !filepath.IsAbs(rsf.RemotePath) {
return errors.Errorf("unexpected relative path: %q", rsf.RemotePath)
}
sshArgs = append(sshArgs, "-p", strconv.Itoa(rsf.Port), rsf.Host, "--", "mkdir", "-p", rsf.RemotePath)
if rsf.Port != 0 {
sshArgs = append(sshArgs, "-p", strconv.Itoa(rsf.Port))
}
sshArgs = append(sshArgs, rsf.Host, "--")
sshArgs = append(sshArgs, "mkdir", "-p", rsf.RemotePath)
sshCmd := exec.Command(sshBinary, sshArgs...)
logrus.Debugf("executing ssh for preparing sshfs: %s %v", sshCmd.Path, sshCmd.Args)
out, err := sshCmd.CombinedOutput()
Expand All @@ -52,7 +56,11 @@ func (rsf *ReverseSSHFS) Start() error {
if !filepath.IsAbs(rsf.RemotePath) {
return errors.Errorf("unexpected relative path: %q", rsf.RemotePath)
}
sshArgs = append(sshArgs, "-p", strconv.Itoa(rsf.Port), rsf.Host, "--", "sshfs", ":"+rsf.LocalPath, rsf.RemotePath, "-o", "slave")
if rsf.Port != 0 {
sshArgs = append(sshArgs, "-p", strconv.Itoa(rsf.Port))
}
sshArgs = append(sshArgs, rsf.Host, "--")
sshArgs = append(sshArgs, "sshfs", ":"+rsf.LocalPath, rsf.RemotePath, "-o", "slave")
if rsf.Readonly {
sshArgs = append(sshArgs, "-o", "ro")
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/sshocker/sshocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func (x *Sshocker) Run() error {
for _, l := range x.LForwards {
args = append(args, "-L", l)
}
args = append(args, "-p", strconv.Itoa(x.Port), x.Host, "--")
if x.Port != 0 {
args = append(args, "-p", strconv.Itoa(x.Port))
}
args = append(args, x.Host, "--")
if len(x.Command) > 0 {
args = append(args, x.Command...)
}
Expand Down

0 comments on commit b89aa7e

Please sign in to comment.