Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 5962

Install kerberos packages using paramiko [duplicate]

$
0
0

I'm trying to automate installation of kerberos packages (krb5-kdc, krb5-admin-server, krb5-user) using python-paramiko library on Ubuntu server.

Ref article: https://www.atlantic.net/dedicated-server-hosting/how-to-setup-kerberos-server-and-client-on-ubuntu/

When i send the command sudo apt install krb5-kdc krb5-admin-server krb5-user -y via ssh, an interactive screen pops up like below:

pop-up.png

So how to send input to this popup? I have tried multiple things and it doesn't seem to work.

I tried following code but it didn't work as expected and threw error.

            conn = paramiko.SSHClient()            conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())            conn.connect(host, username=user, password=psw, port=22)                     chan = conn.invoke_shell()            server_name = "example.demo.com"            cmd = "sudo apt install krb5-kdc krb5-admin-server krb5-user -y"            chan.send(f"{cmd}\n")            support.wait_for_data(chan, output_list=["Default Kerberos version 5 realm:"])            chan.send('DEMO.COM')            chan.send("\n")            support.wait_for_data(chan, output_list=["Kerberos servers for your realm:"])            chan.send(f"{server_name}\n")            support.wait_for_data(chan, output_list=["Administrative server for your Kerberos realm:"])            chan.send(f"{server_name}\n")            support.wait_for_data(chan, output_list=["Setting up a Kerberos Realm"])            chan.send("\n")def wait_for_data(    chan: "paramiko.channel.Channel",    output_list: list = None,    verify_output: bool = True,    timeout: int = 40,):"""    Helper method to check if the channel is ready to receive data    and verify expected data available or not    :param chan: SSH shell channel    :param output_list: Command output list to verify    :param verify_output: If True, validate output.    :param timeout: Timeout in seconds"""    stdout = b""    while True:        # Check if the channel is ready to receive data        if chan.recv_ready():            stdout += chan.recv(10000)        if verify_output:            for val in output_list:                if val in common.to_str(stdout):                    return common.to_str(stdout)        time.sleep(1)        timeout -= 1        if not verify_output and timeout == 0:            return common.to_str(stdout)        if timeout <= 0:            raise SSHError(                f"Did not receive '{output_list}' as expected.\n"                f"Shell output: {stdout}"            )

When i run above code, it fails with below err:exceptions.SSHError: Did not receive '['Kerberos servers for your realm:']' as expected. Shell output: b'DEMO.COM'


Viewing all articles
Browse latest Browse all 5962

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>