kinit from Python script using keytab
Does anyone know how to kinit from within a python script usi开发者_如何学Pythonng keytab; that is to avoid having to prompt for a password?
I prefer use libraries such as krbcontext
:
from krbcontext.context import krbContext
with krbContext(using_keytab=True, principal='[username]@[REALM]', keytab_file='/etc/security/keytabs/[name].keytab', ccache_file='/tmp/krb5cc_pid_appname'):
pass
from subprocess import Popen, PIPE
kinit_args - [ '/usr/bin/kinit', '-kt', '/home/username/username.keytab', 'username@realm' ]
subp = Popen(kinit_args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
subp.wait()
精彩评论