func (d *Driver) mountSharedFolder(shareDir, shareName string) error {
	// create mountpoint and mount shared folder
	addr, err := d.GetSSHHostname()
	if err != nil {
		return err
	}

	port, err := d.GetSSHPort()
	if err != nil {
		return err
	}

	auth := &ssh.Auth{
		Keys: []string{d.GetSSHKeyPath()},
	}

	client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
	if err != nil {
		return err
	}

	command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; [ -f /usr/bin/vmhgfs-fuse ]&& sudo /usr/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs .host:/" + shareName + " " + shareDir

	log.Debugf("About to run SSH command:\n%s", command)
	output, err := client.Output(command)
	log.Debugf("SSH cmd err, output: %v: %s", err, output)
	return err
}
Exemplo n.º 2
0
// uploadKeyPair upload the public key to docker-machine
func (d *Driver) uploadKeyPair() error {

	ipAddr, err := d.GetIP()
	if err != nil {
		return err
	}

	port, _ := d.GetSSHPort()
	auth := ssh.Auth{
		Passwords: []string{d.Password},
	}

	ssh.SetDefaultClient(ssh.Native)
	sshClient, err := ssh.NewClient(d.GetSSHUsername(), ipAddr, port, &auth)
	if err != nil {
		return err
	}
	d.waitForSSHFunc(sshClient, "exit 0")

	publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
	if err != nil {
		return err
	}

	command := fmt.Sprintf("mkdir -p ~/.ssh; echo '%s' > ~/.ssh/authorized_keys", string(publicKey))
	log.Debugf("Upload the public key with command: %s", command)

	output, err := sshClient.Output(command)
	if err != nil {
		log.Debugf("Upload command err, output: %v: %s", err, output)
		return err
	}

	return nil
}
Exemplo n.º 3
0
func (h *Host) CreateSSHClient() (ssh.Client, error) {
	addr, err := h.Driver.GetSSHHostname()
	if err != nil {
		return ssh.ExternalClient{}, err
	}

	port, err := h.Driver.GetSSHPort()
	if err != nil {
		return ssh.ExternalClient{}, err
	}

	auth := &ssh.Auth{
		Keys: []string{h.Driver.GetSSHKeyPath()},
	}

	return ssh.NewClient(h.Driver.GetSSHUsername(), addr, port, auth)
}
Exemplo n.º 4
0
func (c *ComputeUtil) executeCommands(commands []string, ip, sshKeyPath string) error {
	for _, command := range commands {
		auth := &ssh.Auth{
			Keys: []string{sshKeyPath},
		}

		client, err := ssh.NewClient(c.userName, ip, 22, auth)
		if err != nil {
			return err
		}

		if _, err := client.Output(command); err != nil {
			return err
		}
	}
	return nil
}
Exemplo n.º 5
0
func (d *Driver) uploadKeyPair() error {
	ipAddr := d.IPAddress
	port, _ := d.GetSSHPort()
	tcpAddr := fmt.Sprintf("%s:%d", ipAddr, port)

	log.Infof("%s | Waiting SSH service %s is ready to connect ...", d.MachineName, tcpAddr)

	log.Infof("%s | Uploading SSH keypair to %s ...", d.MachineName, tcpAddr)

	auth := ssh.Auth{
		Passwords: []string{d.SSHPassword},
	}

	sshClient, err := ssh.NewClient(d.GetSSHUsername(), ipAddr, port, &auth)

	if err != nil {
		return err
	}

	command := fmt.Sprintf("mkdir -p ~/.ssh; echo '%s' > ~/.ssh/authorized_keys", string(d.PublicKey))

	log.Debugf("%s | Upload the public key with command: %s", d.MachineName, command)

	output, err := sshClient.Output(command)

	log.Debugf("%s | Upload command err, output: %v: %s", d.MachineName, err, output)

	if err != nil {
		return err
	}

	log.Debugf("%s | Upload the public key with command: %s", d.MachineName, command)

	d.fixRoutingRules(sshClient)

	if d.DiskSize > 0 {
		d.autoFdisk(sshClient)
	}

	if d.UpgradeKernel {
		d.upgradeKernel(sshClient, tcpAddr)
	}

	return nil
}
Exemplo n.º 6
0
func (creator *StandardSSHClientCreator) CreateSSHClient(d drivers.Driver) (ssh.Client, error) {
	addr, err := d.GetSSHHostname()
	if err != nil {
		return ssh.ExternalClient{}, err
	}

	port, err := d.GetSSHPort()
	if err != nil {
		return ssh.ExternalClient{}, err
	}

	auth := &ssh.Auth{}
	if d.GetSSHKeyPath() != "" {
		auth.Keys = []string{d.GetSSHKeyPath()}
	}

	return ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
}
Exemplo n.º 7
0
func GetSSHClientFromDriver(d Driver) (ssh.Client, error) {
	address, err := d.GetSSHHostname()
	if err != nil {
		return nil, err
	}

	port, err := d.GetSSHPort()
	if err != nil {
		return nil, err
	}

	auth := &ssh.Auth{
		Keys: []string{d.GetSSHKeyPath()},
	}

	client, err := ssh.NewClient(d.GetSSHUsername(), address, port, auth)
	return client, err

}
func (d *Driver) replaceInsecureSSHKey() error {
	addr, err := d.GetSSHHostname()
	if err != nil {
		return err
	}

	port, err := d.GetSSHPort()
	if err != nil {
		return err
	}

	tempssh, err := ioutil.TempFile(os.TempDir(), "appcatalyst-ssh-insecure-key")
	defer os.Remove(tempssh.Name())

	_, err = tempssh.WriteString(insecureSSHKey)
	if err != nil {
		return err
	}

	auth := &ssh.Auth{
		Keys: []string{tempssh.Name()},
	}

	client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
	if err != nil {
		return err
	}

	pubkey, err := d.readSSHKey()
	if err != nil {
		return err
	}

	command := "echo '" + pubkey + "' > ~/.ssh/authorized_keys"

	log.Debugf("About to run SSH command:\n%s", command)
	output, err := client.Output(command)
	log.Debugf("SSH cmd err, output: %v: %s", err, output)
	return err
}