When I want to login as root, I usually have to type: su -l and than an interactive query starts in order to receive the password.

Is it possible to login as root without this interactive query ?

I tried the following one liners, which did not work:

  • echo "password" | su -l
  • echo "password" | xargs su -l
  • 1
    SSH key-based authentication?
    – cychoi
    Commented Mar 15, 2015 at 17:17

2 Answers 2


Yes it is possible, many ways, but some of the ways are less safe than others. There are two methods I recommend for this.

The first and easiest way is to use sudo with the nopassword option, check the sudo manpage for details.

The second (and more secure) way is to use pam (pluggable authentication modules) with a physical token. This is more complicated, but when done right it is fairly secure.

  • 2
    A third way is ssh to root@localhost, either without passphrase (ouch!) or with ssh-agent set up. But really, compared to echoing plaintext passwords, sudo is way more than sufficiently secure. :) Commented Mar 15, 2015 at 16:36
  • If you are already running ssh, that would be a way to do it, but there are some risks with doing so (not a lot, but some). there are also many other ways, including calife and expect.
    – hildred
    Commented Mar 15, 2015 at 20:35

auth without psw ssh-keygen -t dsa ssh-copy-id -i ~/.ssh/id-dsa.pub root@ip

creates a keyset an copies the public key to the given account+host. so you can login with a simple ssh root@ip without a password

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .