From: Simon Ruderich Date: Sat, 3 Apr 2021 13:57:54 +0000 (+0200) Subject: config: add Host option "ssh_user" X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=023e863fbd9c6cf5bebd18e19c05ae9e60fbbe21;p=safcm%2Fsafcm.git config: add Host option "ssh_user" If it's empty or not present the default user of `ssh` is used. This is either the current user or the user configured in ~/.ssh/config. --- diff --git a/cmd/safcm/config/hosts.go b/cmd/safcm/config/hosts.go index cf750cb..1199687 100644 --- a/cmd/safcm/config/hosts.go +++ b/cmd/safcm/config/hosts.go @@ -31,6 +31,8 @@ type Hosts struct { type Host struct { Name string `yaml:"name"` + + SshUser string `yaml:"ssh_user"` } func LoadHosts() (*Hosts, error) { diff --git a/cmd/safcm/sync.go b/cmd/safcm/sync.go index 09ffe85..7f1e090 100644 --- a/cmd/safcm/sync.go +++ b/cmd/safcm/sync.go @@ -310,7 +310,7 @@ func (s *Sync) Host(wg *sync.WaitGroup) error { }() // Connect to remote host - err := conn.DialSSH(s.host.Name) + err := conn.DialSSH(s.host.SshUser, s.host.Name) if err != nil { return err } diff --git a/rpc/dial.go b/rpc/dial.go index b723e55..40ac7f6 100644 --- a/rpc/dial.go +++ b/rpc/dial.go @@ -32,11 +32,15 @@ import ( "ruderich.org/simon/safcm/remote" ) -func (c *Conn) DialSSH(remote string) error { +func (c *Conn) DialSSH(user, host string) error { if c.events == nil { return fmt.Errorf("cannot reuse Conn") } + remote := host + if user != "" { + remote = user + "@" + host + } c.debugf("DialSSH: connecting to %q", remote) opts := "-eu"