Score:0

'su' command without a passwd prompt in a remote machine while connected through and ssh session using python's paramiko library

ck flag

I am writing a python script to automate ssh connection to a remote machine. When connected to the remote machine using python's Paramiko library, if I need to elevate privileges (specifically to switch users -- either to root or to some normal user), I will execute the command su <some_normal_user> (to switch to a normal user) or su (to switch to the root - by default), but the problem I am facing is that it prompts me to enter a passwd.

I have the users and passwords stored in a yaml file, and I would want the command to be one-liner so that it should not prompt me to enter the password manually.

Is there a way I can resolve this issue?

PS. I looked it up on the web and people say that they don't recommend the way of su command to be executed in one-liner because of security reasons (since one can retrieve the password from bash history). In my case, there is no security issue because the passwords are already there in the yaml file.

waltinator avatar
it flag
`su` is unnecessary because, in addition to `su`s many security problems and inconveniences, there is a better, more flexible replacement. Read `man sudo sudoers`.
us flag
If you are storing usernames and passwords in a file then you have more problems than just having the commands in a history file.
Score:0
cn flag

Use sudo instead of su. The sudo command is much better suited that kind of use. You can precisely configure it in the /etc/sudoers file to permit specific users to run specific commands as specific other users with or without asking for a password.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.