-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-keytab
executable file
·68 lines (55 loc) · 1.71 KB
/
make-keytab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# Copyright (c) 2020 Genome Research Ltd.
#
# Author: Christopher Harrison <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -euo pipefail
source krb.rc
get_password() {
# Prompt for user password
local user="$1"
local password
read -srp "Enter Kerberos password for ${user}: " password
echo "${password}"
}
create_ktutil_script() {
# Create the ktutil script that creates the Kerberos keytab
local user="$1"
local password="$2"
local krb_realm="$3"
local keytab="$4"
for cipher in $(krb_ciphers); do
echo "addent -password -p ${user}@${krb_realm} -k 1 -e ${cipher}"
echo "${password}"
done
echo "wkt ${keytab}"
echo "quit"
}
create_keytab() {
# Create a new Kerberos keytab file for user principal
local user="$1"
local password="$2"
local krb_realm="$3"
local keytab="${user}.keytab"
rm -f "${keytab}"
ktutil < <(create_ktutil_script "${user}" "${password}" "${krb_realm}" "${keytab}") > /dev/null
}
main() {
local user="${1-$(whoami)}"
local password="$(get_password "${user}")"
echo
create_keytab "${user}" "${password}" "$(krb_realm)"
}
main "$@"