There are multiple ways to do so. I wouldn't hardcode your password into the script for the sake of security but as long as you are sure only you are using the script it should be fine. This sample code is not trying to make it secure. I am just answering your question based on the constrains you gave.
If you insist on using os.system
I would propose the following:
# change these 2 lines before
# ideally, opt to use environmental variables instead
PASSWORD="your password"
SSH_ADDRESS="name@ip"
os.system(f"""
/usr/bin/env expect <<EOF
spawn ssh {SSH_ADDRESS}
expect "{SSH_ADDRESS}'s password:"
send "{PASSWORD}\r"
interact
EOF
""")
This will be using the expect
command that lets you automate providing answers to to commands. One of the assumptions is that you have expect
installed on your machine. If not, you will have to do so before attempting to make this work.
Still, I wouldn't encourage you to do so and instead use some package to connect to your server instead. I think it is better to avoid mixing shell commands inside the Python script if you have alternatives.
For instance, take a look at this question and the subprocess module that might be helpful for you. In the latter case, you will not even have to install anything extra on your machine