2

I'm trying to login as root in shell by following command :

$ echo 'myPassword' | sudo -Si

But gets me following error:

stdin: is not a tty
-bash: line 1: myPassword: command not found

My Goal :

I added above command in ~/.bashrc in order to whenever Terminal starts up, it logged in as root

P.S :

I can successfully run below command :

For instance

$ echo 'myPassword' | sudo -S chown $USER ~/file.txt
5

1 Answer 1

1

It's as simple as this:

sudo -i

Update:

Seems like you want to get into root automatically whenever terminal is opened. Well, I'm not going to give you a lesson about security, but instead will provide you a solution:

  1. Get rid of password when doing sudo:

    sudo visudo
    

    And add following line (replace username with whatever you need):

    username ALL=(ALL) NOPASSWD: ALL
    
  2. Next, add following at the end of your ~/.bashrc file:

    sudo -i
    
5
  • See My Goal section in the first post Sep 18, 2014 at 6:48
  • 1
    I don't want to get rid of password entry for everytime I execute sudo -i. I just want to login as root (i.e. sudo -i) without needing to enter it while loading terminal. Look at this code: echo 'myPassword' | sudo -S chown $USER ~/file.txt This one is successfully executed but now look at this: echo 'myPassword' | sudo -S -i Now I receive the mentioned error (stdin: is not a tty) Sep 18, 2014 at 7:11
  • My answer does exactly whay you want, as described in your question. Furthermore, this is contradictory what you have asked: you want to get into root on every terminal start, but you want to keep password for sudo for particular user? What is the reason of having the password for sudo, if the terminal will always be in root anyways? Sep 18, 2014 at 7:37
  • Furthermore, it's already second time when you are stating additional conditions for your question. Stop doing that and mention everything you want in your question! Otherwise, how the hell people can guess what's in your head? Sep 18, 2014 at 7:37
  • Why do people always recommend sudo su? It makes no sense, it is redundant and adds (a negligible) overhead. Just use sudo -i or sudo -s instead.
    – terdon
    Sep 18, 2014 at 10:51

You must log in to answer this question.

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