VMware Cloud Community
divesh_7
Contributor
Contributor

vmware cmdlet to access a vm and set an ssh credential

Hi all,

I have been looking into doing some automation work and the first step for this to work is i need to be able to make sure ssh config are added onto a vm through vmware powershell (or cli interface)

I was wondering if we have a set cmdlet command that would allow me to set the ssh username and password on a linux vm?

Your help would be very much appreciated.

Regards,

Divesh.

Tags (1)
7 Replies
jpsider
Expert
Expert

I'm not aware of a specific command.

you can use 'invoke-vmscript' to run a command(or script) on a vm.

divesh_7
Contributor
Contributor

Hi jpsider,

Yeah after looking on the VMware site, it appears there isn't a cmdlet that would allow you to do that.

I think a script would be required to achieve that.

Does anyone have a script that allows you to access a Linux vm through powershell and configure it with either ssh or telnet. The idea is as soon as I have configured the vm with ssh/telnet, I would use an automated tool to log into the vm using ssh/telnet and do certain checks, perform certain actions (including AD integrate the vm) and then delete the temporary ssh/telnet credential that I originally created through powershell.

Any advice/pointers/help would be much appreciated.

Regards,

D

Reply
0 Kudos
jpsider
Expert
Expert

Not sure what flavor of Linux, but this will get you close, you'll need to create you own script and copy it to the Vm's like this

Copy-VMGuestFile -Source "C:\temp\enablSSH.sh" -Destination "/LocalDropbox/enableSSH.sh" -LocalToGuest -vm $vmname -GuestUser $VMUN -GuestPassword $VMPW

Then execute like

Invoke-VMScript -ScriptText "/bin/bash /LocalDropbox/enableSSH.sh" -VM $vmname -GuestUser $VMUN -GuestPassword $VMPW -ErrorAction SilentlyContinue

divesh_7
Contributor
Contributor

Hi jpspider,

I have created a script and followed the procedure you mentioned. However, I am getting the following error message:

pastedImage_0.png

Any idea why it is complaining that the script exist? It should be existing for me to run it isn't it?

Also can I assume you do not need to make the script executable before using the invoke-VMscript cmdlet?

Thanks.

Regards,

D

Reply
0 Kudos
jpsider
Expert
Expert

hmmm, that is the output of the script you ran. It is not saying that the script itself exists.

Can you post your script you created to enable ssh?

Reply
0 Kudos
divesh_7
Contributor
Contributor

Hi jpsider,

Issue is now fixed and it's all working as expected now.

This was not really the output of the script; I was getting the message because I called my script "adduser.sh" and since this is already a known Linux function, it was complaining. I changed the name and it worked!

Thanks a lot for your input, much appreciated! Smiley Happy

Reply
0 Kudos
jpsider
Expert
Expert

-scripttype BASH

May have helped.  Sorry!

Reply
0 Kudos