bash 编写 Kerberos Ktutil 脚本以制作密钥表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37454308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Script Kerberos Ktutil to make keytabs
提问by OrigamiEye
I want to make a script that will generate the a keytab using ktutil. When running the script I want to use [user]$ script.sh PASSWORD
我想制作一个使用 ktutil 生成密钥表的脚本。运行脚本时,我想使用 [user]$ script.sh PASSWORD
#script.sh
echo "addent -password -p PRINCIPAL -k 1 -e aes256-cts-hmac-sha1-96" | ktutil
Ktutil than needs a password, here I want to use the PASSWORD argument from above. How would I pass the password arguement?
Ktutil 需要密码,这里我想使用上面的 PASSWORD 参数。我将如何通过密码争论?
回答by Cyrus
With GNU bash:
使用 GNU bash:
user="PRINCIPAL"
pass="topsecret"
printf "%b" "addent -password -p $user -k 1 -e aes256-cts-hmac-sha1-96\n$pass\nwrite_kt $user.keytab" | ktutil
printf "%b" "read_kt $user.keytab\nlist" | ktutil
Output:
输出:
slot KVNO Principal ---- ---- --------------------------------------------------------------------- 1 1 PRINCIPAL@YOURDOMAIN
回答by Tagar
A version in Python
Python 中的一个版本
https://github.com/Tagar/stuff/blob/master/keytab.py
https://github.com/Tagar/stuff/blob/master/keytab.py
piping password to ktutil in shell is not secure as password will be visible in list of processes.
将密码传递给 shell 中的 ktutil 是不安全的,因为密码将在进程列表中可见。
Since this Python scripts just interacts with ktutil using pexpect library, it's possible to implement the same as a pure shell script using expect.
由于该Python脚本只是ktutil使用Pexpect的库交互,它可以实现与使用纯shell脚本期待。
Hope this helps.
希望这可以帮助。
回答by Lokendra Jain
To create the multiple orgs keytabs and default hbase,pipe,hdfs keytab at the same time you can run the below script, which i have just created:
要同时创建多个组织密钥表和默认的 hbase、pipe、hdfs 密钥表,您可以运行我刚刚创建的以下脚本:
#!/bin/bash
read -p "Please enter space-delimited list of ORGS to create: " NEW_ORGS
clear
#echo "################# CREATE KEYTABS ############################"
#echo ""
kdestroy
for i in $NEW_ORGS
do
printf "%b" "addent -password -p ${i} -k 1 -e aes256-cts-hmac-sha1-96\n${i}\nwrite_kt ${i}.keytab" | ktutil
printf "%b" "read_kt ${i}.keytab\nlist" | ktutil
done
echo ""
if [ ! -e /home/eip/.keytabs/hbase.keytab ]
then
printf "%b" "addent -password -p hbase -k 1 -e aes256-cts-hmac-sha1-96\nhbase\nwrite_kt hbase.keytab" | ktutil
printf "%b" "read_kt hbase.keytab\nlist" | ktutil
fi
exit 0