Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh improvements #1055

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
12 changes: 10 additions & 2 deletions libvirt/uri/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (u *ConnectionURI) dialSSH() (net.Conn, error) {
username = sshu
}

hostname, err := sshcfg.Get(u.Hostname(), "HostName")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get() doesn't return an error when the key is not found, so this will result in the hostname ~never being read from the URI directly (i.e. it will only work when there is an alias in ~/.ssh/config).

And yes, the username thing immediately above is also broken.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, #1059 fixes all of these

if err != nil {
hostname = u.Hostname()
}

cfg := ssh.ClientConfig{
User: username,
HostKeyCallback: hostKeyCallback,
Expand All @@ -142,10 +147,13 @@ func (u *ConnectionURI) dialSSH() (net.Conn, error) {

port := u.Port()
if port == "" {
port = defaultSSHPort
port, err = sshcfg.Get(u.Host, "Port")
if err != nil {
port = defaultSSHPort
}
}

sshClient, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", u.Hostname(), port), &cfg)
sshClient, err := ssh.Dial("tcp", net.JoinHostPort(hostname, port), &cfg)
if err != nil {
return nil, err
}
Expand Down