How To Become Root In Ubuntu: 10 Steps (with Pictures) - WikiHow
Có thể bạn quan tâm
- Log in / Sign up
- Use Sudo to Run Commands |
- Enable & Log In as Root |
- Root Login at the Login Screen |
- Root Login via SSH |
- Video |
- Q&A |
- Tips
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. There are 7 references cited in this article, which can be found at the bottom of the page. This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources. This article has been viewed 1,232,080 times. Learn more...
To run administrative tasks in Linux, you must have root (also known as superuser) access. While having a separate root account is common in most Linux distributions, Ubuntu disables root logins by default. To run commands with root permissions, it's best to use sudo. However, if you must log in as root or get a root shell, it's easy to enable the root account. This guide will teach you multiple ways to become root in Ubuntu Linux.
Becoming Root in Ubuntu: Quick Options
- To run a command as root, type sudo before the rest of the command (e.g., sudo vim /etc/httpd.conf).
- To enable the root user, use sudo passwd rt to create a root account and passwd.
- To access a root shell after enabling root, use su -.
Steps
Method 1 Method 1 of 4:Running Root Commands with Sudo
-
1 Press Ctrl+Alt+T to open a terminal window.[1] Because Ubuntu locks the root account by default, you cannot use su to become root as you would in other Linux distributions.[2] Instead, start your commands with sudo. - If you want to enable the root user in Ubuntu so you can log in as root, see Enabling the Root User. We don't recommend doing this for security reasons, but it is possible.
-
2 Type sudo before the rest of your command. “Sudo” stands for “substitute user do.” When you add sudo to the beginning of a command, the command will run as root. - For example: sudo /etc/init.d/networking stop stops the network service, and sudo adduser adds a new user to the system. Both of these tasks require root access.
- You will be prompted to enter your password before sudo runs the command. Linux stores your password for 15 minutes, so you won’t have to keep typing it.
-
3 Use sudo -H before running a command that opens a program with a Graphical User Interface (GUI). For security reasons, Ubuntu does not recommend using “sudo” to open programs with GUIs.[3] However, this should work for most programs if you absolutely must. - The gksudo command is now deprecated in Ubuntu.
-
4 Give sudo access to another user. If you are setting up an account for someone who does not currently have root access, you will need to add their username to the sudo group. To do this, type usermod -aG sudo username (but replace “username” with the correct username). Advertisement
Enabling Root Login
-
1 Press Ctrl+Alt+T to open a terminal window. For security purposes (and to avoid damage), the root user account is locked by default in Ubuntu. If you must have a root login (if a program your business uses requires it, or this workstation will only be used by a single user), you can enable the root user with some simple commands.[4] - Enabling the root user can put your system at risk and is not recommended by Ubuntu.[5]
-
2 Type sudo passwd root and press ↵ Enter. You will be prompted to set a new password for the root user. Don’t lose this password. -
3 Enter a password, then press ↵ Enter. -
4 Retype the password when prompted, then press ↵ Enter. The root user should now have a password. -
5 Type su - and press ↵ Enter. Enter the root password when prompted to arrive at the root prompt. - To disable the root account, type sudo passwd -l root.[6]
Advertisement
Enabling Root Login in at the Ubuntu Login Screen
-
1 Press Ctrl+Alt+T to open a terminal window. If you've enabled the root user, you won't be able to log in to the Ubuntu GUI as root unless you enable root GUI login. We really don't recommend doing this, but it is possible.[7] - If you haven't enabled the root user yet, use this method to do so.
-
2 Use su - to become root. As long as you've enabled the root user, this will give you a root shell. When prompted for a password, enter the root password you've set for Ubuntu. -
3 Open /etc/gdm3/custom.conf in a text editor. Use sudo to run the command. For example, if you use vim as your text editor, use sudo vim /etc/gdm3/custom.conf. -
4 Add a new entry. Here's what you'll need to add: - Under "TimedLogInDelay = 10", open a new line.
- Type AllowRoot=True.
- Save your changes and close the file.
-
5 Edit /etc/pam.d/gdm-password for editing. Again, use sudo, e.g., sudo vim /etc/pam.d/gdm-password if you prefer vim. -
6 Comment out the line "auth required pam_succeed_If." To do this, enter a hash symbol (#) before the line: # auth required pam_succeed_If.[8] - When you're finished, save and close the file.
- To log in as root on the login screen, select Not Listed from the login menu, then type root as the user. Enter the root password to log in.
- To disable root login at the GUI login screen, simply delete the line you added to /etc/gdm3/custom.conf and uncomment the line you commented in etc/pam.d/gdm-password.
Advertisement
Enabling Root Login via SSH in Ubuntu
-
1 Open /etc/ssh/sshd_config in any text editor. You'll need root access to edit this file, so open it using sudo. For example, if you want to open it in vim, use sudo vim /etc/ssh/sshd_config.[9] - If you haven't enabled the root user yet, use this method to do so.
-
2 Uncomment the PermitRootLogin line. The line you're looking for is #PermitRootLogin prohibit-password. To uncomment, just remove the hashmark at the beginning. -
3 Replace prohibit-password with yes. The line should now look like PermitRootLogin yes.[10] -
4 Restart sshd. To do this, use sudo systemctl restart ssh. This allows the root user to log in via SSH. - To reverse this, just comment out the line again.
Advertisement
Community Q&A
Search Add New Question- Question I read the article and tried gksudo on Ubuntu, but it doesn't work. I learned that it is abolished by most flavors of Linux. What do I do?
Thomas J. Jordan Sr. Community Answer gksudo won't work in a Wayland session; switch to an Xorg session and try. Thanks! We're glad this was helpful. Thank you for your feedback. If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Yes No Not Helpful 13 Helpful 24 - Question How to administer password created by command?
Jisjo Community Answer You can create a root password by command line. In Linux root has Administrator like the Windows Operating system. Use this below command to set root password: $ sudo passwd root. Thanks! We're glad this was helpful. Thank you for your feedback. If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Yes No Not Helpful 6 Helpful 7 - Question i did the steps for enabling and setting password for root but after typing: " sudo - " it still says su: Authentication failure. What should I do?
Jisjo Community Answer The error "su: Authentication failure" shows for an incorrect password login. Give the correct password to fix this. Also, there is no command like "sudo - ", refer to the article for correct usage. Thanks! We're glad this was helpful. Thank you for your feedback. If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Yes No Not Helpful 5 Helpful 9
Video
Tips
- You can use su to access the shell of another user on the system. To become user “jane," type su - jane and then enter YOUR password when prompted (not Jane’s). Thanks Helpful 3 Not Helpful 2
- Avoid logging in as root as much as possible. You can run almost any superuser-required command withsudo. Thanks Helpful 2 Not Helpful 5
You Might Also Like
References
- ↑ https://help.ubuntu.com/community/UsingTheTerminal
- ↑ https://help.ubuntu.com/community/RootSudo
- ↑ https://help.ubuntu.com/community/RootSudo#Graphical_sudo
- ↑ https://ubuntu.com/tutorials/command-line-for-beginners#3-opening-a-terminal
- ↑ https://ubuntu.com/server/docs/user-management
- ↑ https://ubuntu.com/server/docs/user-management
- ↑ https://ubuntu.com/tutorials/command-line-for-beginners#3-opening-a-terminal
- ↑ https://access.redhat.com/solutions/64860
- ↑ https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/v2v_guide/preparation_before_the_p2v_migration-enable_root_login_over_ssh
- ↑ https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/v2v_guide/preparation_before_the_p2v_migration-enable_root_login_over_ssh
About This Article
To run a command as root, type “sudo” before the command. Use “gksudo” if the command opens a program with a Graphical User Interface (GUI). Did this summary help you?YesNo
In other languages Spanish Italian Portuguese Russian German Indonesian Arabic Thai Dutch French Korean Hindi Vietnamese Turkish Chinese Persian Japanese- Send fan mail to authors
Is this article up to date?
Yes No
Advertisement Cookies make wikiHow better. By continuing to use our site, you agree to our cookie policy. Quizzes & Games
You Might Also Like
Trending Articles
Watch Articles
Trending Articles
Quizzes & Games
- Categories
- Computers and Electronics
- Operating Systems
- Linux
- Ubuntu
- Home
- About wikiHow
- Experts
- Jobs
- Contact Us
- Site Map
- Terms of Use
- Privacy Policy
- Do Not Sell or Share My Info
- Not Selling Info
- Contribute
Follow Us
×wikiHow Tech Help:
Tech troubles got you down? We've got the tips you need
Subscribe You're all set! X --Từ khóa » đăng Nhập Ubuntu Với Quyền Root
-
Kích Hoạt đăng Nhập Với Tài Khoản Root Trên Ubuntu Desktop
-
Hướng Dẫn Kích Hoạt đăng Nhập SSH Với Tài Khoản Root Trên Ubuntu
-
Cách đăng Nhập Bằng Ubuntu Root - Parada Creativa ▷➡️
-
Cách đăng Nhập Với Quyền Root Ubuntu - Hrm
-
Hướng Dẫn Kích Hoạt SSH Cho User Root Trên Hệ điều Hành Ubuntu
-
Cách Tạo User Sudo Trên Ubuntu Giúp Có Quyền Truy Cập Như User Root
-
Cách Bật Và Tắt Tài Khoản Người Dùng Root Trong Ubuntu - Android 2022
-
Enable Tài Khoản Root Trong Ubuntu
-
Chạy Terminal Dưới Dạng Root Trong Ubuntu - WebSetNet
-
Cách Bật Hoặc Tắt Người Dùng Root Trên Linux
-
Hướng Dẫn Bật Root Trên Ubuntu Server 18.04 & Cấp Quyền SSH
-
Root Là Gì? Làm Sao để Trở Thành Root Trong Linux?
-
Tạo Sudo Cho User Mới Trên Ubuntu 20.04 [Quickstart]