Skip to content

Commit ba4761c

Browse files
authored
Merge pull request #160 from arduino/ssh_public_key
Allow login with private key and on a different port
2 parents 95de9d6 + 2eda7cd commit ba4761c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

upload/upload.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"path/filepath"
1515
"regexp"
1616
"runtime"
17+
"strconv"
1718
"strings"
1819
"time"
1920

@@ -29,8 +30,10 @@ var Busy = false
2930

3031
// Auth contains username and password used for a network upload
3132
type Auth struct {
32-
Username string `json:"username"`
33-
Password string `json:"password"`
33+
Username string `json:"username"`
34+
Password string `json:"password"`
35+
PrivateKey string `json:"private_key"`
36+
Port int `json:"port"`
3437
}
3538

3639
// Extra contains some options used during the upload
@@ -375,8 +378,19 @@ func form(port, board, file string, auth Auth, l Logger) error {
375378
func ssh(port string, files []string, commandline string, auth Auth, l Logger, SSH bool) error {
376379
debug(l, "Connect via ssh ", files, commandline)
377380

381+
if auth.Port == 0 {
382+
auth.Port = 22
383+
}
384+
378385
// Connect via ssh
379-
client, err := simplessh.ConnectWithPassword(port+":22", auth.Username, auth.Password)
386+
var client *simplessh.Client
387+
var err error
388+
if auth.PrivateKey != "" {
389+
client, err = simplessh.ConnectWithKey(port+":"+strconv.Itoa(auth.Port), auth.Username, auth.PrivateKey)
390+
} else {
391+
client, err = simplessh.ConnectWithPassword(port+":"+strconv.Itoa(auth.Port), auth.Username, auth.Password)
392+
}
393+
380394
if err != nil {
381395
return errors.Wrapf(err, "Connect via ssh")
382396
}

0 commit comments

Comments
 (0)