kerberos常用基本命令

  • 授权添加yarn账户 

    
    
    
    
  1. [root@xxx ~] # kadmin.local
  2. Authenticating as principal cloudera-scm/[email protected] with password.
  3. kadmin.local: addprinc [email protected]
  4. WARNING: no policy specified for [email protected]; defaulting to no policy
  5. Enter password for principal "[email protected]":
  6. Re-enter password for principal "[email protected]":
  7. Principal "[email protected]" created.
  8. kadmin.local: exit
  •  查看当前系统使用的Kerberos账户

   
   
   
   
  1. #使用的 cloudera-scm
  2. [root@xxx ~] # klist
  3. Ticket cache: FILE: /tmp/krb5cc_ 0
  4. Default principal: cloudera-scm/[email protected]
  5. Valid starting Expires Service principal
  6. 2019-08- 06T14: 45: 54 2019-08- 07T14: 45: 54 krbtgt/[email protected]
  7. renew until 2019-08- 13T14: 45: 54

注意:这里 Expires 是过期时间,即我们使用kinit 授权时候是有有效期的 

有效期设置对应配置文件  /etc/krb5.conf 中的 ticket_lifetime = 24h 参数 (修改时服务端与客户端同时修改)

  • 退出授权 - kdestroy

   
   
   
   
  1. [root@ecs-dbtest- 0003 kerberos] # klist
  2. Ticket cache: FILE: /tmp/krb5cc_ 0
  3. Default principal: admin/[email protected]
  4. Valid starting Expires Service principal
  5. 10/ 17/ 2019 10: 17: 27 10/ 18/ 2019 10: 17: 27 krbtgt/[email protected]
  6. renew until 10/ 24/ 2019 10: 17: 27
  7. [root@ecs-dbtest- 0003 kerberos] # kdestroy
  8. [root@ecs-dbtest- 0003 kerberos] # klist
  9. klist: No credentials cache found (filename: /tmp/krb5cc_ 0)
  • 使用Kerberos账户

   
   
   
   
  1. [root@xxx ~] # kinit yarn #这里yarn是通过 kadmin.local addprinc yarn@JAST.COM 创建的
  2. Password for yarn@JAST. COM: #这里输入密码

然后使用root用户读/写/执行hdfs权限即为yarn用户


   
   
   
   
  1. [root@xxx ~] # hdfs dfs -put index.html /tmp
  2. [root@xxx ~] # hdfs dfs -ls /tmp
  3. Found 6 items
  4. drwxrwxrwx - hdfs supergroup 0 2019-08- 06 15: 56 /tmp/.cloudera_health_monitoring_canary_files
  5. drwxr-xr- x - yarn supergroup 0 2019- 07- 17 09: 37 /tmp/hadoop-yarn
  6. drwx-- x-- x - hbase supergroup 0 2019- 07- 01 13: 37 /tmp/hbase-staging
  7. drwx-wx-wx - hive supergroup 0 2019- 07- 02 16: 16 /tmp/hive
  8. -rw-r--r-- 2 yarn supergroup 2381 2019-08- 06 15: 57 /tmp/index.html
  9. drwxrwxrwt - mapred hadoop 0 2019- 07- 18 21: 38 /tmp/logs
  • 创建keytab文件

   
   
   
   
  1. [root@xxx jast] # kadmin.local -q "xst -norandkey -k hdfs.keytab [email protected]"
  2. Authenticating as principal hdfs/[email protected] with password.
  3. Entry for principal [email protected] with kvno 1, encryption type aes256-cts-hmac-sha1 -96 added to keytab WRFILE:hdfs.keytab.
  4. Entry for principal [email protected] with kvno 1, encryption type aes128-cts-hmac-sha1 -96 added to keytab WRFILE:hdfs.keytab.
  5. Entry for principal [email protected] with kvno 1, encryption type des3-cbc-sha1 added to keytab WRFILE:hdfs.keytab.
  6. Entry for principal [email protected] with kvno 1, encryption type arcfour-hmac added to keytab WRFILE:hdfs.keytab.
  7. Entry for principal [email protected] with kvno 1, encryption type camellia256-cts-cmac added to keytab WRFILE:hdfs.keytab.
  8. Entry for principal [email protected] with kvno 1, encryption type camellia128-cts-cmac added to keytab WRFILE:hdfs.keytab.
  9. Entry for principal [email protected] with kvno 1, encryption type des-hmac-sha1 added to keytab WRFILE:hdfs.keytab.
  10. Entry for principal [email protected] with kvno 1, encryption type des-cbc-md5 added to keytab WRFILE:hdfs.keytab.
  • 命令行使用keytab 

   
   
   
   
  1. [root@xxx jast] # kinit -kt hdfs.keytab hdfs@JAST.COM
  2. [root@xxx jast] # klist
  3. Ticket cache: FILE:/tmp/krb5cc_ 0
  4. Default principal: [email protected]
  5. Valid starting Expires Service principal
  6. 2019-08- 07 T13: 35 : 19 2019-08-08 T13: 35 : 19 krbtgt/[email protected]
  7. renew until 2019-08- 14 T13: 35 : 19

 

创建keytab不同用户,即便密码相同,也不可共用keytab


   
   
   
   
  1. [root@xxx jast] # kinit -kt hdfs.keytab [email protected]
  2. kinit: Keytab contains no suitable keys for [email protected] while getting initial credentials

 

  • 合并多个 keytab 为一个 keytab

   
   
   
   
  1. [root@xxx jast]# ktutil
  2. ktutil: rkt hdfs .keytab #读取多个 keytab
  3. ktutil: rkt yarn .keytab
  4. ktutil: wkt hdfs-nb .keytab #合并为一个 hdfs-nb .keytab , 即这个文件可以使用 hdfsyarnkeytab
  5. ktutil: exit

在当前目录可以看到生成的 hdfs-nb.keytab

验证:


   
   
   
   
  1. [root@xxx jast] # kinit -kt hdfs.keytab yarn@JAST.COM #使用hdfs的keytab,登录yarn用户,报错
  2. kinit: Keytab contains no suitable keys for [email protected] while getting initial credentials
  3. [root@xxx jast] # kinit -kt hdfs-nb.keytab yarn@JAST.COM #使用合并的keytab,登录yarn用户,成功
  4. [root@xxx jast] # klist
  5. Ticket cache: FILE:/tmp/krb5cc_ 0
  6. Default principal: [email protected]
  7. Valid starting Expires Service principal
  8. 2019-08- 07 T13: 43 : 06 2019-08-08 T13: 43 : 06 krbtgt/[email protected]
  9. renew until 2019-08- 14 T13: 43 : 06
  10. [root@xxx jast] # kinit -kt hdfs-nb.keytab hdfs@JAST.COM #使用合并的keytab,登录hdfs用户,成功
  11. [root@xxx jast] # klist
  12. Ticket cache: FILE:/tmp/krb5cc_ 0
  13. Default principal: [email protected]
  14. Valid starting Expires Service principal
  15. 2019-08- 07 T13: 44 : 19 2019-08-08 T13: 44 : 19 krbtgt/[email protected]
  16. renew until 2019-08- 14 T13: 44 : 19
  • 查看keytab内容

   
   
   
   
  1. [root@xxx jast] # klist -k -e hdfs.keytab
  2. Keytab name: FILE:hdfs.keytab
  3. KVNO Principal
  4. ---- --------------------------------------------------------------------------
  5. 1 [email protected] (aes256-cts-hmac-sha1- 96)
  6. 1 [email protected] (aes128-cts-hmac-sha1- 96)
  7. 1 [email protected] (des3-cbc-sha1)
  8. 1 [email protected] (arcfour-hmac)
  9. 1 [email protected] (camellia256-cts-cmac)
  10. 1 [email protected] (camellia128-cts-cmac)
  11. 1 [email protected] (des-hmac-sha1)
  12. 1 [email protected] (des-cbc-md5)
  13. [root@fwqml006 jast] # klist -k -e hdfs-nb.keytab
  14. Keytab name: FILE:hdfs-nb.keytab
  15. KVNO Principal
  16. ---- --------------------------------------------------------------------------
  17. 1 [email protected] (aes256-cts-hmac-sha1- 96)
  18. 1 [email protected] (aes128-cts-hmac-sha1- 96)
  19. 1 [email protected] (des3-cbc-sha1)
  20. 1 [email protected] (arcfour-hmac)
  21. 1 [email protected] (camellia256-cts-cmac)
  22. 1 [email protected] (camellia128-cts-cmac)
  23. 1 [email protected] (des-hmac-sha1)
  24. 1 [email protected] (des-cbc-md5)
  25. 1 [email protected] (aes256-cts-hmac-sha1- 96)
  26. 1 [email protected] (aes128-cts-hmac-sha1- 96)
  27. 1 [email protected] (des3-cbc-sha1)
  28. 1 [email protected] (arcfour-hmac)
  29. 1 [email protected] (camellia256-cts-cmac)
  30. 1 [email protected] (camellia128-cts-cmac)
  31. 1 [email protected] (des-hmac-sha1)
  32. 1 [email protected] (des-cbc-md5)
  • spark授权 启动指定keytab
spark-submit --principal hdfs@JAST.COM --keytab hdfs-nb.keytab --jars $(echo lib/*.jar | tr ' ' ',') --class com.jast.test.Test data-filter-1.0-SNAPSHOT.jar 

   
   
   
   

 

你可能感兴趣的:(kerberos)