Есть Telegram bot нужно подключить его к linux серверу

Есть Telegram bot нужно подключить его к linux серверу. С такими условиями Когда срабатывает if. Бот давал команду по ssh на сервер допустим:

useradd {Случайное имя} && passwd {Случайное имя}

{Случайный пароль}

При этом нужно получить это случайное имя и пароль. И отправить тому человеку кто задал такую команду if


Ответы (1 шт):

Автор решения: D. Violet

useradd:

def random_name():
    alphabet = string.ascii_letters
    while True:
        random_name = ''.join(choice(alphabet) for i in range(8))
        if (any(symbol.islower() for symbol in uis_password)
                and any(symbol.isupper() for symbol in uis_password)):
            return random_name

passwd:

def random_password():
    alphabet = string.ascii_letters + string.digits
    while True:
        random_password = ''.join(choice(alphabet) for i in range(8))
        if (any(symbol.islower() for symbol in uis_password)
                and any(symbol.isupper() for symbol in uis_password)
                and sum(symbol.isdigit() for symbol in uis_password) >= 1):
            return random_password

ssh:

def ssh_connect():
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    name = random_name()
    pass = random_password()

    client.connect(hostname=, username=, password=, port=)
    stdin, stdout, stderr = client.exec_command('useradd ' + name + '&& passwd ' + pass )
    data = stdout.read().decode('utf-8').strip('\n')
    client.close()
→ Ссылка