Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libvirt/uri/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (u *ConnectionURI) parseAuthMethods(target string, sshcfg *ssh_config.Confi
// construct the whole ssh connection, which can consist of multiple hops if using proxy jumps,
// the ssh configuration file is loaded once and passed along to each host connection.
func (u *ConnectionURI) dialSSH() (net.Conn, error) {
var sshcfg* ssh_config.Config = nil
var sshcfg *ssh_config.Config = nil

sshConfigFile, err := os.Open(os.ExpandEnv(defaultSSHConfigFile))
if err != nil {
Expand Down Expand Up @@ -277,13 +277,14 @@ func (u *ConnectionURI) dialHost(target string, sshcfg *ssh_config.Config, depth
// cfg.User value defaults to u.User.Username()
if sshcfg != nil {
sshu, err := sshcfg.Get(target, "User")
if err != nil {
log.Printf("[DEBUG] ssh user for target '%v' is overridden to '%v'", target, sshu)
if err == nil && sshu != "" && cfg.User == "" {
// get username from ~/.ssh/config
// if uri doesn't contains username
log.Printf("[DEBUG] ssh user for target '%v' is set to '%v'", target, sshu)
cfg.User = sshu
}
}


cfg.Auth = u.parseAuthMethods(target, sshcfg)
if len(cfg.Auth) < 1 {
return nil, fmt.Errorf("could not configure SSH authentication methods")
Expand Down