we modified the part of using sudo in the Keys rotation:
// *************************************************************************** // Use another account's credentials to update the keys.
// ***************************************************************************
sendCommand( updatePublicKeyCommand );
sendCommand( createAuthorizedKeysBackupFileCommand );
if ( ( oldPublicKey != null ) && !oldPublicKey.isEmpty() ) {
sendCommand( deauthorizedOldPublicKeyCommand, false );
sendCommand( replaceAuthorizedKeysFileCommand );
}
sendCommand( updateAuthorizedKeysCommand );
sendCommand( resetPublicKeyPermissionsCommand );
sendCommand( resetAuthorizedKeysPermissionsCommand ); sendCommand( resetAuthorizedKeysBackupPermissionsCommand );
Now the rotation using root password account works fine to rotate root ssh-keys, so we can fulfill the ESXi use case without need for 2nd local account.
Attached the updated ESXi credential script to manage Keys on SSH