1

In the python 3 script I need to enter a few commands under root priveleges via asyncssh.

Something like this code sample:

async with asyncssh.connect(host=IP, port=PORT, username=ORDINARY_USER, password=PASSWORD, known_hosts=None) as conn:
    result_su = await conn.run('echo "verysecretpass" | su', check=False)
    result_1 = await conn.run("root_command1", check=False)
    print(result_1.stdout)
    result_2 = await conn.run("root_command2", check=False)
    print(result_2.stdout)

This sample is not working of course. What changes are needed to make it work?

1 Answer 1

1

Instead of su you may use sudo with the -S switch which reads the password from STDIN:

echo <password> | sudo -S <command>

Credits to sudo with password in one command-line.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.