How to check if running as root? Not asking for sudo
I am a new Ubuntu user and am still getting used to the OS. I have been using it primarily for local testing of a site that I am developing. I downloaded the LAMP stack for this.
When I first downloaded Ubuntu, whenever I edited the files I was developing, I needed to enter sudo nano filename
. It was not like this for files in my home directory, only for files where I was testing.
When I logged on today, I didn't have to enter sudo
, I was able to just enter nano filename
and edit the files. I am not sure if I somehow disabled the need for a sudo
password, which I would not want to do.
I ran grep root /etc/passwd
then grep root /etc/shadow
which denied access without entering sudo
. When I did, root:!
showed.
From what I read, that means the account is disabled.
I don't know if that means I disabled the password or if the account is locked and everything is ok.
Is there a way to make sure that I am not running as root and if I currently am how to disable it so I am running only as admin.
Also, why did the sudo
password suddenly stop needing to be entered for editing my files?
Thanks for your answers, if my question is unclear, please let me know so that I can try to clarify.
If you are using bash (the default), your prompt will tell you if you are acting as root. If it ends in a '$
' you are running as a normal user. If it ends in a '#
' you are running as root.
Additionally,
whoami
will show who you are.
If you can suddenly edit files that used to require sudo access, my first suspicion would be that you've somehow managed to change the permissions on a file. If you type:
ls -l <filename>
and examine the results, the rwx sections show permissions.
-rw-rw-r-- 1 user user 77338 Oct 21 17:59 filename.odt
|\ /\ /\ /
| | | +-- permissions for "other": every user on the system.
| | +----- permissions for "group"
| +-------- permissions for "owner"
+---------- filetype (- is regular file)
If you belong to a group that has write permissions or if "other" has write permissions then you don't need sudo access to write to the file.
You can read an introduction to linux permissions for more details on file permissions.
You only need to use root to edit files owned by root or other users. Any files that you create or own can be edited by you without using root.
E.g. run the following commands
cd $HOME
touch test.txt
nano test.txt
The above commands navigated to your home directory (your personal area), created a file called test.txt, then entered the file using an editor called nano.
Now if you try:
nano /etc/apt/sources.list
You should be able to see the file but get a warning saying that you cannot edit the file.
This is because even though the file is not owned by you, the file has read access for everyone. This can be shown in the picture below:
To easily view the permissions in Ubuntu, just type:
ll /path/to/parent/directory
or alternatively for other systems such as debian
ls -al /path/to/directory
There are lots of great on-line tutorials for reading about user permissions, such as this, that I recommend reading. I quite often see people do silly things such as set everything in /var/www to 777 to get their webserver to "work" because they don't understand linux permissions and thus their servers are less secure.
I am a new ubuntu user...
Good luck and welcome to Linux! Spread the word.