Hello@Sami Ahmad,
CAUTION: Retrieving the keytab resets the secret for the Kerberos principal. This renders all other keytabs for that principal invalid.
The correct answer depends on which Kerberos implementation you are using.
For MIT KDC, a system admin would use an interface, known as "kadmin" (or an alternative "kadmin.local"), to create keytab for users using 'ktadd' command. ktadd will regenerate key with a random password and then add it to keytab:
# ktadd -k </path/to/file.keytab> <principal-name>
For FreeIPA, an admin would use ipa-getkeytab command. This command can generate keytab with a random or provided password:
# ipa-getkeytab -s <ipaserver.example.com> -p <principal-name> -k </path/to/file.keytab>
For Microsoft AD, an admin should use ktpass command. This command is really useful when you want to generate a keytab for AD service principal to be used in Linux environment. This can also use a given password or a random password (+rndpass):
# ktpass /princ hive/sandbox.hortonworks.com@HWX.COM /pass <password> /mapuser hiveservice /pType KRB5_NT_PRINCIPAL /crypto ALL /out c:\temp\hive.service.keytab
Hope this helps!