Changing user and group ownership
When a file is owned by the wrong user or group, the error can be repaired with the commands
(change owner) and chgrp
(change group). Changing the file ownership is a
frequent system administrative task in environments where files need to be shared in a group.
Changing the default file ownership of a software package after its installation to a specific
user is often necessary to protect the integrity of your server. Both commands are very flexible.
Use the --help option to find out more.
command can be applied to change both the user and group ownership of a file,
changes only the group ownership. Of course the system will check if the user
issuing one of these commands has sufficient permissions on the files or directories that the
user wants to modify the ownership attributes.
In order to only change the user ownership of a file, you can use the following syntax:
chown newuser file
. If you use a colon and a group name after the user name
(chown newuser:newgroup file
), group ownership will be changed as well.
The omission of the group name defaults to the group of the user name specified before the colon.
On a dedicated server, you will need to be logged in as root to change the user or group ownership
of a file for security reasons. If the usage of these commands is not be restricted, an intruder
or malicious user can assign ownership of files to other users and/or groups and change behavior
of those users' environments. This scenario can cause great damage to other users' or systems' files.
The following example changes the file ownership of the .jpg file from brucelee to root.
[email@example.com ~]# ls -al 69*
-rw-r--r-- 1 brucelee brucelee 26508 2008-11-09 12:08 188.8.131.52.us.jpg
[firstname.lastname@example.org ~]# chown root: 184.108.40.206.us.jpg
[email@example.com ~]# ls -al 69*
-rw-r--r-- 1 root root 26508 2008-11-09 12:08 220.127.116.11.us.jpg
ls is one of the must-know Linux command
to perform daily administrative function.
It has a large number of options to show files and directories on your server. You probably will
never have to use all options supported by ls, but you should try to see what it can do. The --help
option shows a summarized list of parameters for ls.
In general, the simplest long form of ls would list each of the files in the current directory and
the files permissions, the size of the file, date of the last modification, and the file name or
directory. Following is an example of a directory listing using ls -l. For each line shown,
the first column is the file permission setting. The second column indicates the number of
subdirectories within a directory. The default amount of directories is always 2
because of the . and .. directories. The third and fourth column are the file ownership:
user and group name. The fifth column is the file size or directory size. The sixth and seventh
column show the date and time of last modification of the file. The file name or directory is
shown in the final column.
[firstname.lastname@example.org ~]$ ls -l
-rw-r--r-- 1 root root 26508 2008-11-09 12:08 69.jpg
-rwxrwxrwx 1 brucelee brucelee 26753 2008-11-09 04:22 76.jpg
drwxrwxr-x 2 brucelee brucelee 4096 2008-11-08 13:30 bugs
drwxrwxr-x 2 brucelee brucelee 147456 2008-11-09 16:33 flash
drwxrwxr-x 2 brucelee brucelee 20480 2008-11-04 07:03 samples
You should note that Linux uses the symbol ~ (tilde), . (single dot), and .. (double dot)
to indicate the home directory of the login user, the current directory, and the parent
Useful forms of ls
List the contents of your home directory by adding a tilde after the ls command.
List the contents of the root directory (entire file system on your server).
List the contents of the parent directory.
List the contents of all sub directories.
ls -d */
Only list the directories in the current directory.