本文整理汇总了Golang中github.com/docker/machine/libmachine/ssh.GenerateSSHKey函数的典型用法代码示例。如果您正苦于以下问题:Golang GenerateSSHKey函数的具体用法?Golang GenerateSSHKey怎么用?Golang GenerateSSHKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenerateSSHKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createSSHKey
func (d *Driver) createSSHKey() error {
log.Debug("Creating Key Pair...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
return nil
}
示例2: createSSHKey
func (d *Driver) createSSHKey() (*godo.Key, error) {
if d.SSHKeyFingerprint != "" {
key, resp, err := d.getClient().Keys.GetByFingerprint(d.SSHKeyFingerprint)
if err != nil && resp.StatusCode == 404 {
return nil, fmt.Errorf("Digital Ocean SSH key with fingerprint %s doesn't exist", d.SSHKeyFingerprint)
}
return key, err
}
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
createRequest := &godo.KeyCreateRequest{
Name: d.MachineName,
PublicKey: string(publicKey),
}
key, _, err := d.getClient().Keys.Create(createRequest)
if err != nil {
return key, err
}
return key, nil
}
示例3: createSSHKey
func (d *Driver) createSSHKey() (*packngo.SSHKey, error) {
sshKeyPath := d.GetSSHKeyPath()
log.Debugf("Writing SSH Key to %s", sshKeyPath)
if err := ssh.GenerateSSHKey(sshKeyPath); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(sshKeyPath + ".pub")
if err != nil {
return nil, err
}
createRequest := &packngo.SSHKeyCreateRequest{
Label: fmt.Sprintf("docker machine: %s", d.MachineName),
Key: string(publicKey),
}
key, _, err := d.getClient().SSHKeys.Create(createRequest)
if err != nil {
return key, err
}
return key, nil
}
示例4: generateCertForAzure
func (d *Driver) generateCertForAzure() error {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
cmd := exec.Command("openssl", "req", "-x509", "-key", d.GetSSHKeyPath(), "-nodes", "-days", "365", "-newkey", "rsa:2048", "-out", d.azureCertPath(), "-subj", "/C=AU/ST=Some-State/O=InternetWidgitsPtyLtd/CN=\\*")
return cmd.Run()
}
示例5: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return err
}
// Libvirt typically runs as a deprivileged service account and
// needs the execute bit set for directories that contain disks
for dir := d.ResolveStorePath("."); dir != "/"; dir = filepath.Dir(dir) {
log.Debugf("Verifying executable bit set on %s", dir)
info, err := os.Stat(dir)
if err != nil {
return err
}
mode := info.Mode()
if mode&0001 != 1 {
log.Debugf("Setting executable bit set on %s", dir)
mode |= 0001
os.Chmod(dir, mode)
}
}
log.Debugf("Creating VM data disk...")
if err := d.generateDiskImage(d.DiskSize); err != nil {
return err
}
log.Debugf("Defining VM...")
tmpl, err := template.New("domain").Parse(domainXMLTemplate)
if err != nil {
return err
}
var xml bytes.Buffer
err = tmpl.Execute(&xml, d)
if err != nil {
return err
}
vm, err := d.conn.DomainDefineXML(xml.String())
if err != nil {
log.Warnf("Failed to create the VM: %s", err)
return err
}
d.VM = &vm
d.vmLoaded = true
return d.Start()
}
示例6: createKeyPair
// createKeyPair create keypair for ssh to docker-machine
func (d *Driver) createKeyPair() error {
log.Debugf("SSH key path:%s", d.GetSSHKeyPath())
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
return nil
}
示例7: Create
func (d *Driver) Create() error {
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return err
}
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating VM...")
virtualSwitch, err := d.chooseVirtualSwitch()
if err != nil {
return err
}
log.Infof("Using switch %q", virtualSwitch)
diskImage, err := d.generateDiskImage()
if err != nil {
return err
}
if err := cmd("New-VM",
d.MachineName,
"-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")),
"-SwitchName", quote(virtualSwitch),
"-MemoryStartupBytes", toMb(d.MemSize)); err != nil {
return err
}
if d.CPU > 1 {
if err := cmd("Set-VMProcessor",
d.MachineName,
"-Count", fmt.Sprintf("%d", d.CPU)); err != nil {
return err
}
}
if err := cmd("Set-VMDvdDrive",
"-VMName", d.MachineName,
"-Path", quote(d.ResolveStorePath("boot2docker.iso"))); err != nil {
return err
}
if err := cmd("Add-VMHardDiskDrive",
"-VMName", d.MachineName,
"-Path", quote(diskImage)); err != nil {
return err
}
log.Infof("Starting VM...")
return d.Start()
}
示例8: createSSHKey
func (d *Driver) createSSHKey() (string, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return "", err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return "", err
}
return string(publicKey), nil
}
示例9: createKeyPair
// createKeyPair - generate key files needed
func (d *Driver) createKeyPair() error {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return err
}
log.Debugf("created keys => %s", string(publicKey))
d.SSHPublicKey = string(publicKey)
return nil
}
示例10: Create
// Create creates a GCE VM instance acting as a docker host.
func (d *Driver) Create() error {
log.Infof("Generating SSH Key")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
log.Infof("Creating host...")
c, err := newComputeUtil(d)
if err != nil {
return err
}
return c.createInstance(d)
}
示例11: createSSHKey
func (d *Driver) createSSHKey() (*vultr.SSHKey, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
key, err := d.getClient().CreateSSHKey(d.MachineName, string(publicKey))
if err != nil {
return &key, err
}
return &key, nil
}
示例12: createKeyPair
func (d *Driver) createKeyPair() error {
log.Debugf("%s | SSH key path: %s", d.MachineName, d.GetSSHKeyPath())
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err
}
publicKey, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return err
}
d.PublicKey = publicKey
return nil
}
示例13: generateKeyBundle
// Make a boot2docker userdata.tar key bundle
func (d *Driver) generateKeyBundle() (*bytes.Buffer, error) {
magicString := "boot2docker, please format-me"
log.Infof("Creating SSH key...")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
// magicString first so the automount script knows to format the disk
file := &tar.Header{Name: magicString, Size: int64(len(magicString))}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(magicString)); err != nil {
return nil, err
}
// .ssh/key.pub => authorized_keys
file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return nil, err
}
file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return nil, err
}
if err := tw.Close(); err != nil {
return nil, err
}
return buf, nil
}
示例14: createSSHKey
func (d *Driver) createSSHKey() (*SSHKey, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
key, err := d.getClient().SSHKey().Create(d.deviceConfig.Hostname, string(publicKey))
if err != nil {
return nil, err
}
return key, nil
}
示例15: createSSHKey
func (d *Driver) createSSHKey() (*api.SSHKey, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err
}
publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, err
}
createRequest := &api.SSHKeyCreateRequest{
Name: d.MachineName,
Key: string(publicKey),
}
key, _, err := d.getClient().SSHKey.Create(createRequest)
return key, err
}