I need to write a python script which must be able to connect to a remote server (to user1), execute some commands (this was easy), then it must switch to user2 through sudo su - user2, and execute some commands (the problem is here). How can make it switch to user2 without asking me the password (I can put the password somewhere in the script), and execute commands as user2.
Thanks,