Changing Ownership Security Settings On Linux
Sometimes, you need to change the owner of a file, such as when someone leaves an organization or a developer creates an application that needs to be owned by a system account when it’s in production. Linux provides two commands for doing that. The chown command makes it easy to change the owner of a file, and the chgrp command allows you to change the default group of a file.
The format of the chown command is:
chown options owner[.group] file
You can specify either the login name or the numeric UID for the new owner of the file:
# chown dan newfile
# ls -l newfile
-rw-rw-r— 1 dan rich 0 Sep 20 19:16 newfile
#
Simple. The chown command also allows you to change both the user and group of a file:
# chown dan.shared newfile
# ls -l newfile
-rw-rw-r— 1 dan shared 0 Sep 20 19:16 newfile
#
If you really want to get tricky, you can just change the default group for a file:
# chown .rich newfile
# ls -l newfile
-rw-rw-r— 1 dan rich 0 Sep 20 19:16 newfile
#
Finally, if your Linux system uses individual group names that match user login names, you can change both with just one entry:
# chown test. newfile
# ls -l newfile
-rw-rw-r— 1 test test 0 Sep 20 19:16 newfile
#
The chown command uses a few different option parameters. The -R parameter allows you to make changes recursively through subdirectories and files, using a wildcard character.
The -h parameter also changes the ownership of any files that are symbolically linked to the file.
The chgrp command provides an easy way to change just the default group for a file or directory:
$ chgrp shared newfile
$ ls -l newfile
-rw-rw-r— 1 rich shared 0 Sep 20 19:16 newfile
$
The user account must own the file, and be a member of the new group as well to be able to change the group. Now any member in the shared group can write to the file. This is one way to share files on a Linux system. However, sharing files among a group of people on the system can get tricky. The next section discusses how to do this.
Changing Ownership Security Settings On Linux |
The format of the chown command is:
chown options owner[.group] file
You can specify either the login name or the numeric UID for the new owner of the file:
# chown dan newfile
# ls -l newfile
-rw-rw-r— 1 dan rich 0 Sep 20 19:16 newfile
#
Simple. The chown command also allows you to change both the user and group of a file:
# chown dan.shared newfile
# ls -l newfile
-rw-rw-r— 1 dan shared 0 Sep 20 19:16 newfile
#
If you really want to get tricky, you can just change the default group for a file:
# chown .rich newfile
# ls -l newfile
-rw-rw-r— 1 dan rich 0 Sep 20 19:16 newfile
#
Finally, if your Linux system uses individual group names that match user login names, you can change both with just one entry:
# chown test. newfile
# ls -l newfile
-rw-rw-r— 1 test test 0 Sep 20 19:16 newfile
#
The chown command uses a few different option parameters. The -R parameter allows you to make changes recursively through subdirectories and files, using a wildcard character.
The -h parameter also changes the ownership of any files that are symbolically linked to the file.
Note
Only the root user can change the owner of a file. Any user can change the default group of a file, but the user must be a member of the groups the file is changed from and to.
The chgrp command provides an easy way to change just the default group for a file or directory:
$ chgrp shared newfile
$ ls -l newfile
-rw-rw-r— 1 rich shared 0 Sep 20 19:16 newfile
$
The user account must own the file, and be a member of the new group as well to be able to change the group. Now any member in the shared group can write to the file. This is one way to share files on a Linux system. However, sharing files among a group of people on the system can get tricky. The next section discusses how to do this.
0 Response to "Changing Ownership Security Settings On Linux"
Post a Comment