VMware Cloud Community
haiiampc
Enthusiast
Enthusiast

Can we change -> SSH config value -> "permitrootlogin=yes" - via "Power CLI"??

We have "Large Number of ESX & ESXi" hosts (But "PermitRoonLogin=No" in /etc/ssh/sshd_config)

Any idea, can we change all hosts to --> PermitRootLogin --> YES --> via Power CLI

Thank you in advance..

Regards - Purna

If it helps --> Please award points - as appropriate - "Correct" or "Helpful"
0 Kudos
7 Replies
haiiampc
Enthusiast
Enthusiast

Yeah.. it requires to modify /etc/ssh/sshd_config --> file

and "Service sshd restart" also..

Do I have "excess expectation" via "PowerCLI" 🙂  ???

If it helps --> Please award points - as appropriate - "Correct" or "Helpful"
0 Kudos
haiiampc
Enthusiast
Enthusiast

http://communities.vmware.com/message/1228094

As per LucD -> SSH Service can be restarted via ->  Start-VmHostService "cmdlet"

--> Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "TSM-SSH"} | Start-VMHostService

Now all I need is -> How to modifiy "PermitRootLogin=yes" -> in "/etc/ssh/sshd_config" ??? (Currently it is "no")

Curious 🙂

If it helps --> Please award points - as appropriate - "Correct" or "Helpful"
0 Kudos
LucD
Leadership
Leadership

With ESX you can edit that file via SSH.

With ESXi it's a bit more tricky and most probably not supported.

In the PowerCLI Reference book we showed a way of doing this through the Get-VMHostFirmware and Set-VMHostFirmware cmdlets.

And don't forget that you have to make sure that your change survives a reboot.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
haiiampc
Enthusiast
Enthusiast

Hmm.. Confused with that.. 🙂

Please provide "Power Shell Example command" - if you can..

which can change to --> "PermitRootLogin=yes"

If it helps --> Please award points - as appropriate - "Correct" or "Helpful"
0 Kudos
LucD
Leadership
Leadership

Are you using ESX or ESXi ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
haiiampc
Enthusiast
Enthusiast

Hi,

We need to do "PermitRootLogin-yes" on --> ESX5i  (via PowerCli 5.0)

If it helps --> Please award points - as appropriate - "Correct" or "Helpful"
0 Kudos
Grzesiekk
Expert
Expert

Hi there,

i don't know the possibility in doing this directly from powershell. One way is to use plink.

function set-hostrootlogin([string]$esxentry){

$str1=’c:\plink.exe -v -pw ”v53HYfsd#$%$%^^&*” -l root ‘
$str2=’ sed -i "s/PermitRootLogin no/PermitRootLogin yes/g" /etc/ssh/sshd_config’
$esxhost=”‘”+$esxentry+”‘”
$command=$str1+$esxhost+$str2
$esxentry.name >> $outfile
Invoke-Expression -Command $command
}


assuming you have plink.exe in c:\  and password of -pw ”v53HYfsd#$%$%^^&*”  Smiley Wink

This should work., You can make a powershell function which is more customizable from this if you need.

set-hostrootlogin "yourhost.yourdomain.local"

Smiley Wink

Regards,

Greg

--- @blog https://grzegorzkulikowski.info
0 Kudos