refactor: more seamless SSH connections
continuous-integration/drone/push Build is passing Details

This commit is contained in:
decentral1se 2021-10-25 11:13:41 +02:00
parent 9e0d77d5c6
commit 3d46ce6db2
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 12 additions and 37 deletions

View File

@ -316,14 +316,10 @@ to start running Abra commands against it.
This command can also provision your server ("--provision/-p") so that it is
capable of hosting Co-op Cloud apps. Abra will default to expecting that you
have a working SSH config for the host in your ~/.ssh/config file. E.g. for
"example.com", you'll want to have something like:
Host example.com
Hostname 192.168.178.31 # domain name also works
User myuserontheserver
Port 12345
IdentityFile ~/.ssh/mysecretkey.local
have a running ssh-agent and are using SSH keys to connect to your new server.
Abra will also read your SSH config (matching "Host" as <domain>). SSH
connection details precedence follows as such: command-line > SSH config >
guessed defaults.
If you have no SSH key configured for this host and are instead using password
authentication, you may pass "--ssh-auth password" to have Abra ask you for the
@ -345,7 +341,7 @@ Example:
abra server add --provision --traefik varia.zone glodemodem 12345
Abra will construct the following SSH connection string then:
Abra will construct the following SSH connection and Docker context:
ssh://globemodem@varia.zone:12345

View File

@ -84,20 +84,7 @@ Your new Hetzner Cloud VPS has successfully been created! Here are the details:
VPS IP address: %s
VPS Root Password: %s
Here is what your SSH configuration (~/.ssh/config) might look like:
Host %s.example.com
Hostname %s
User root
Port 22
IdentityFile ~/.ssh/<your-ssh-private-key>
Remember, your "Host" value must be a valid publicly accessible domain name as
Abra uses this domain to identity servers. If you specified "--ssh-auth
password" then you may skip the IdentityFile stanza.
Once your SSH client is configured, you can access this new VPS via SSH using
the following command:
You can access this new VPS via SSH using the following command:
ssh root@%s
@ -107,7 +94,6 @@ record new") and add the server to your Abra configuration ("abra server add")
to have a working server that you can deploy Co-op Cloud apps to.
`,
internal.HetznerCloudName, ip, rootPassword,
internal.HetznerCloudName, ip,
ip,
))

View File

@ -1,7 +1,6 @@
package ssh
import (
"fmt"
"os/user"
"github.com/AlecAivazis/survey/v2"
@ -19,7 +18,7 @@ type HostConfig struct {
}
// GetHostConfig retrieves a ~/.ssh/config config for a host.
func GetHostConfig(hostname, username, port string, hasIdentityFile bool) (HostConfig, error) {
func GetHostConfig(hostname, username, port string) (HostConfig, error) {
var hostConfig HostConfig
var host, idf string
@ -47,13 +46,12 @@ func GetHostConfig(hostname, username, port string, hasIdentityFile bool) (HostC
}
}
dummyVal := "~/.ssh/identity"
if idf = ssh_config.Get(hostname, "IdentityFile"); (idf == dummyVal || idf == "") && hasIdentityFile {
return hostConfig, fmt.Errorf("SSH identity file missing for %s from SSH config", hostname)
}
idf = ssh_config.Get(hostname, "IdentityFile")
hostConfig.Host = host
hostConfig.IdentityFile = idf
if idf != "" {
hostConfig.IdentityFile = idf
}
hostConfig.Port = port
hostConfig.User = username
@ -66,12 +64,7 @@ func GetHostConfig(hostname, username, port string, hasIdentityFile bool) (HostC
func New(domainName, sshAuth, username, port string) (*simplessh.Client, error) {
var client *simplessh.Client
hasIdentityFile := true
if sshAuth == "password" {
hasIdentityFile = false
}
hostConfig, err := GetHostConfig(domainName, username, port, hasIdentityFile)
hostConfig, err := GetHostConfig(domainName, username, port)
if err != nil {
return client, err
}