How do I add a standard user into sudoers' file using `echo`?

16,518

Not Recommended:

First login as root using the following command:

sudo -i

Then type:

echo "username ALL=(ALL) ALL" >> /etc/sudoers

Change username with your user name.

It will add the username to sudoers file. But doing this may lock out you from sudo.

Recommended:

If you want to edit your /etc/sudoers use visudo

sudo visudo

You can use /etc/sudoers.d instead of modifying /etc/sudoers.

For more see here.

Share:
16,518

Related videos on Youtube

Jatttt
Author by

Jatttt

Updated on September 18, 2022

Comments

  • Jatttt
    Jatttt over 1 year

    I am using Ubuntu 12.04 and I was doing through a terminal tutorial. There was explained about echo command and he mentioned something about adding your name to the sudoers file using echo >>. I am just wondering what it was? Can anyone tell me how to do it?

    • Jatttt
      Jatttt about 10 years
      I went to /bin and typed ls and the first file was bash so i think i should type echo jatin >> bash but i am not sure so just asking? :|
    • Braiam
      Braiam about 10 years
      Please, don't ever do this!
    • terdon
      terdon about 10 years
      1) do not ever try to echo something >> /bin/bash that will break your shell. 2) Do not ever use echo to modify sudoers, use visudo instead. If you found a guide telling you to use echo for this, change guides and ignore anything else it recommends.
  • Jatttt
    Jatttt about 10 years
    Realy realy thank you but how can a standard user do it
  • g_p
    g_p about 10 years
    Only users having root privileged can do it,standard users can't.
  • steeldriver
    steeldriver about 10 years
    Downvoted because the way you have suggested to use sudo simply won't work in this context (it is the redirect >> that needs elevated permissions)
  • Radu Rădeanu
    Radu Rădeanu about 10 years
    @steeldriver Now it will work