How can I log in with the su command in one line in the terminal? I know that the sudo command can do that:

echo [password] | sudo -S [command]

But when I try to imply it in the su command :

echo [password] | su [username]

I get en error:

standard in must be tty

I don't have access to the sudo account (so I can't access and edit the sudoers file).

I know that the right syntax is basically:

su [username]

What I want to do is to add a su command to aliases without being needed to enter password every time

  • 1
    you can't, the error message is pretty clear; see also larsks' answer here – don_crissti Jul 5 '16 at 10:52
  • The synatax is incorrect for su – LXGA Jul 5 '16 at 11:34

The sytax is like so : su [username]. Press enter and now it will request the password for the user [username]

  • I know how to login with the su command. The problem is that I can't submit the password in the same line. Basically, what I want to achieve eventually, is to add to the aliases file a command such as: alias switch "echo [password] | su [username]" – user3561602 Jul 6 '16 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.