Configuring krb5 on a Linux system:
* Install the krb5 packages:
```bash
sudo apt-get install krb5-user krb5-config
```
Configuring the Kerberos client:
* Edit the `/etc/krb5.conf` file to include the realm and KDC information:
```plaintext
[libdefaults]
default_realm = EXAMPLE.COM
[realms]
EXAMPLE.COM = {
kdc = kdc.example.com
admin_server = kdc.example.com
}
[domain_realm]
.example.com = EXAMPLE.COM
example.com = EXAMPLE.COM
```
Obtaining a Ticket Granting Ticket (TGT):
```bash
kinit username
```
Listing active Kerberos tickets:
```bash
klist
```
Destroying active Kerberos tickets:
```bash
kdestroy
```
Using the `krbV` library to authenticate with Kerberos:
```python
import krbV
def get_ticket(username, password, realm='EXAMPLE.COM', kdc='kdc.example.com'):
# Initialize Kerberos context
context = krbV.default_context()
# Create a principal for the user
principal = krbV.Principal(name=username, context=context)
# Set up credentials cache
ccache = krbV.CCache(name=krbV.CCache().generate(), context=context)
# Get Ticket Granting Ticket (TGT)
tgt = krbV.TGT(principal=principal, password=password, realm=realm, kdc=kdc, context=context)
# Store the TGT in the credentials cache
ccache.init(principal=principal)
ccache.store(tgt)
print(f"Successfully obtained TGT for {username}")
return ccache
# Example usage
ccache = get_ticket('myusername', 'mypassword')
```
Using `requests_kerberos` to authenticate HTTP requests with Kerberos:
```python
import requests
from requests_kerberos import HTTPKerberosAuth, REQUIRED
url = 'http://example.com/protected/resource'
# Set up Kerberos authentication
auth = HTTPKerberosAuth(mutual_authentication=REQUIRED)
# Make a request to the protected resource
response = requests.get(url, auth=auth)
if response.status_code == 200:
print("Authenticated successfully!")
print(response.content)
else:
print(f"Failed to authenticate. Status code: {response.status_code}")
```