I used this snippet to generated what needed to be added to get coreos to accept my ssh key on my mac. This was done after the vm was created and could probably be done smoother using vmware's CLI, I just dont know it yet.
# -*- coding: utf-8 -*-
# @Author: cody
# @Date: 2018-02-23 16:13:01
# @Last Modified 2018-02-26
# @Last Modified time: 2018-02-26 15:34:44
''' this script gives you what you need to add to get ssh working on coreos
in VMWare fusion on a mac '''
# example target file
# Documents/Virtual\ Machines.localized/coreos_test.vmwarevm/coreos_test.vmx
import os
from os import environ
from base64 import b64encode
import sys
__home__ = environ['HOME']
prompt = globals()['raw_input' if sys.version_info<(3,0) else 'input']
ssh_pub_key = os.path.join(__home__, '.ssh/id_rsa.pub')
# command shortcuts
bash = lambda cmd: os.popen(cmd).read().strip()
ssh_keygen = lambda: bash('ssh-keygen -t rsa -b 4096')
find_vmx = lambda name: bash("find ~/Documents -name '{}.vmx'".format(name))
# shit to deal with base64 encoding files/strings
only_bytes = lambda b: b if type(b)==bytes else b.encode()
b64 = lambda s: b64encode(only_bytes(s)).decode()
b64_file = lambda path: open(path, 'r').read()
# prompt for the system_name
system_name = prompt('please enter the vm name: ').strip()
# find the .vmx file
vmx_path = find_vmx(system_name)
if len(vmx_path) == 0:
exit('couldnt find a .vmx file for - {}'.format(system_name))
# ensure there is a ssh key in the normal spot
if not os.path.isfile(ssh_pub_key):
ssh_keygen()
# b64 encode the ssh key for coreos config
b64_ssh_key = b64_file(ssh_pub_key)
# this config is for core os
config_template = '''#cloud-config
ssh_authorized_keys:
- "{b64_ssh_key}"
hostname: "{system_name}"'''.format(**locals())
# uncomment this for debug
#print(config_template)
# this is the additional config data
for_vmx = '''
guestinfo.coreos.config.data = "{}"
guestinfo.coreos.config.data.encoding = "base64"
'''.format(b64(config_template))
def vmx_has_been_configured():
''' returns true if the .vmx file has been configured '''
with open(vmx_path, 'r') as f:
return for_vmx in f.read()
# check that the .vmx hasnt already been configured
if vmx_has_been_configured():
exit('it looks like you have already configured - {}'.format(vmx_path))
print("pasting this at the bottom of your virtual machine\'s .vmx file\n")
print(for_vmx)
with open(vmx_path, 'a') as f:
f.write(for_vmx)
if vmx_has_been_configured():
exit("YAY it looks like everything worked!!!")
else:
exit("something went wrong while configuring {}".format(vmx_path))