Reputation: 150
I'm trying to create a virtual machine programmatically with ssh public key using azure java SDK. I saw the create vm example and there we can see:
request.getOsProfile().setAdminUsername(adminUsername);
request.getOsProfile().setAdminPassword(adminPassword);
My question is - what should I set to this OsProfile in order to create a VM with the SSH public key from the attached image?
Upvotes: 1
Views: 290
Reputation: 24128
According to the property linuxConfiguration
of the request json body for the REST API Create or update a VM
, as @Steven said, it's correct and great for setting the SshConfiguration
& LinuxConfiguration
for OSProfile
.
Thanks for Steven's sharing.
Upvotes: 1
Reputation: 804
You could set the LinuxConfiguration
property in OSProfile
. Here is the sample code:
// Set up SSH public key
String fullStorePath = " ~/.ssh/authorized_keys";
String sshKeyData = "you-ssh-key-data";
SshPublicKey sshPublicKey = new SshPublicKey();
sshPublicKey.setPath(fullStorePath);
sshPublicKey.setKeyData(sshKeyData);
// SShConfiguration
ArrayList<SshPublicKey> keyList = new ArrayList<SshPublicKey>();
keyList.add(sshPublicKey);
SshConfiguration sshConfig = new SshConfiguration();
sshconfig.setPublicKeys(keyList);
// Linux Configuration
Bool shouldDisablePasswordAuthentication = False;
LinuxConfiguration linuxConfig = new LinuxConfiguration();
linuxConfig.setSsh(sshConfig);
linuxConfig.setDisablePasswordAuthentication(shouldDisablePasswordAuthentication);
// set your OSProfile now
request.getOsProfile().setLinuxConfiguration(linuxConfig);
// you code goes here
Upvotes: 2