chown
change file owner and group
Synopsis
chown
[OPTION]... [OWNER][:[GROUP]]
FILE...
chown [OPTION]... --reference=RFILE
FILE...
add an example, a script, a trick and tips
examples
chown root /u
Change the owner of /u to "root".
chown root:staff /u
Likewise, but also change its group to "staff".
chown -hR root /u
Change the owner of /u and subfiles to "root".
source
chown -R nobody:nobody *.py
chown -R nobody:nobody gluon
chown -R nobody:nobody scripts
chown -R nobody:nobody applications/*/modules/
chown -R nobody:nobody applications/*/modules/
chown -R nobody:nobody applications/*/models/
chown -R nobody:nobody applications/*/controllers/
source
cp /home/student/backupFiles/bin_backup/chown
/bin/chown
chmod 755 /bin/chown
/bin/chown root /bin/chown
source
Allow specific user permission to read/write my folder
If you are using Linux with a relatively modern
filesystem (ext3/ext4, btrfs, ntfs), this can be done with
POSIX ACLs:
-
Enable ACLs for the filesystem. This is only necessary for
ext3 and ext4 on kernels older than 2.6.38. All other
filesystems that support ACLs enable them automatically.
mount -o remount,acl /
tune2fs -o acl /dev/<partition>
-
Give tom
access to the folder:
setfacl -m user:tom:rwx /home/samantha/folder
If the OS or the filesystem does not support ACLs, another way is
to use groups.
-
Create a group.
-
Some Linux distributions create a separate group for each
user: tom
would automatically be in a group
also named tom
.
-
If not, create a group. This should work on Linux...
groupadd tom
gpasswd -a tom tom
...and this - on BSD:
groupadd tom
usermod -G tom tom
-
chgrp
the directory to that group, and give
permissions with chmod
:
chgrp tom /home/samantha/folder
chmod g+rwx /home/samantha/folder
source
How to make a file editable by two different users in different groups?
Rather than modify permissions on the directory, it might be
easier to put the user john into the www
group.
Users can be in multiple groups. Use either usermod, edit the
/etc/group
file, or if you have a GUI on your linux
machine use the graphical user manager program (might be called
different names based upon distro and desktop environment). The
easiest method is probably to open a command prompt, and type in:
sudo usermod -G www -a john
It'll ask for your account password, and once you enter it, the
user john will be have group level access to the /home/www
directory.
This is assuming the group www already has read/write/execute
access to the /home/www directory If that group doesn't have that
level of access then use chgrp www /home/www
and
chmod g+rwx /home/www
to take care of that.
note: if you are currently logged in as 'john', you may need to
log out and back in for your permissions to update.
source
Why unprivileged user can't change file ownership?
Well, if anyone could change the ownership, then anyone could
change the permissions to gain access to any file on the system.
This is bad not only from a malware standpoint (no sudo
required), but from the standpoint of a sysadmin. If any of the
users could change any of the files, then file permissions are
useless.
source
How to chmod and chown hidden files in Linux?
*
doesn't include hidden files by default, but if
you're in bash, you can do this with:
shopt -s dotglob
Read more about it in bash's
builtin
manual:
If set, Bash includes filenames beginning with a `.' in the
results of filename expansion.
This will make *
include hidden files too.
chmod -R 775 *
Disable it with:
shopt -u dotglob
source
Multiple Users with owner rights?
Permissions on Unix filesystems only have one user. Use group
permissions to give multiple people write access.
source
How to chown/chmod all files in current directory?
I think you want this:
chown username:groupname *
If you also want to recursively change subdirectories, you'll
need the -R
(-r
is deprecated) switch:
chown -R username:groupname *
source
Accidentally ran "chown -R ubuntu:ubuntu /", how to repair?
You have few choices here:
- Restore from backup.
- If no backup, then take files you need into safe location
(USB/network storage) and perform reinstall.
Anything else will be just a waste of your time. Yes, you can
possibly restore permissions but trust me - this will take way
too long! Reinstall, be careful in the future.
With command like that I always advise to use full
path!
You might have issues with ssh, mta etc. Some log files might not
work correctly. There are some commands which require special
permissions. Too much really to be sure!
source
Accidentally changed the owner of /bin and other directories
I would start with sudo chown -R root /bin /sbin /lib /usr
/sys /boot /etc /dev
from inside the chroot - This should
get you a bootable system, but I'm not 100% sure. Might want to
wait for someone to confirm that this won't make the situation
worse.
Note, if you simply chown'd the files, you're in a much better
position than someone who chmod'd or chgrp'd their system. Most
files on a single-user system (i.e., used just by you) are either
owned by you (in /home/username) or owned by root. There might be
a few weird files in /var
and there are definately
some in /run
and /tmp
which are owned
by the services that created them. Try sudo chown root /var
/run /tmp
(note the lack of -R
) for those
directories.
You will probably then want to wipe out the /run
and
/tmp
contents (sudo rm -rf /run/*
/tmp/*
- Be very careful that this is typed correctly),
since they are transient and rebuilt by applications when the
system is restarted, and this is much easier than trying to track
down the owners and fix that.
/var
is going to be a complicated mess. Many daemons
expect to be able to write there (mysql, apache, etc.), and have
folders nested inside. It's safe to reowner the the top-level
contents (sudo chown root /var/*
), but the stuff in
the folders needs to be restored carefully. You might look in the
live-cd's /var
folders for some hints.
source
Always create files/folders but only write to those the user owns
This cannot be reliably done with POSIX ACLs – if you make
subdirectories writable by default, files will also become
writable by default.
-
To allow creation of files, give write rights (rwx) to the
directory. "Default ACLs" can help with this: set
d:g:twousers:rwX
on the directory (assuming both
users are in the twousers
group), and all newly
created items will inherit that.
-
To forbid modification of other users' files, do nothing. The
standard umask setting (022) already ensures that newly
created files will only be writable by the owner (rw/r/r).
However, if the directory has "default ACLs" set as in #1,
these ACLs will be added to newly created files too.
(Remember, though, that only the owner can change
(chmod) a file's permissions. So other users cannot make a
file writable if it isn't already.)
-
To forbid deletion of other users' files, set the sticky bit
on the directory. It cannot be inherited, unfortunately.
As you can see, points #1 and #2 conflict (default ACLs apply to
all objects regardless of type).
You could sort of achieve this by teaching users to
chmod +t,g+w
every new directory they create, but
this is not particularly reliable.
A solution would be to use NFSv4 ACLs , which can be marked as
inheritable by files only or directories only. Unfortunately,
they are not supported by Linux natively, requiring kernel
patches to be applied. If you're into that stuff, nfs4acl
and ngacl are two implementations.
One place in which Windows does the job
better.
source
Understanding file ownership Linux
you understand that rwxrwxrwx are the permissions for your
files/folders right? the first three RWXrwxrwx is for the owner
of the file. The second set of three, rwxRWXrwx is for the group
owner of the file or folder and the last set of three, rwxrwxRWX
is for everyone else on the system. R = read, W = write, and X =
execute.
Chown just assigns the user and the group to the file/folder
If I'm off the mark clarify your question.
source
Allow specific user permission to read/write my folder
If you are using Linux with a relatively modern
filesystem (ext3/ext4, btrfs, ntfs), this can be done with
POSIX
ACLs:
-
Enable ACLs for the filesystem. This is only necessary for
ext3 and ext4 on kernels older than 2.6.38. All other
filesystems that support ACLs enable them automatically.
mount -o remount,acl /
tune2fs -o acl /dev/<partition>
-
Give tom
access to the folder:
setfacl -m user:tom:rwx /home/samantha/folder
If the OS or the filesystem does not support ACLs, another way is
to use groups.
-
Create a group.
-
Some Linux distributions create a separate group for each
user: tom
would automatically be in a group
also named tom
.
-
If not, create a group. This should work on Linux...
groupadd tom
gpasswd -a tom tom
...and this - on BSD:
groupadd tom
usermod -G tom tom
-
chgrp
the directory to that group, and give
permissions with chmod
:
chgrp tom /home/samantha/folder
chmod g+rwx /home/samantha/folder
source
Transmission-daemon not picking up on watch directory
The solution is to give your dropbox folder permissions of 775
sudo chmod -R 775 ~/Dropbox
source
some doubts about chown command in linux?
Simply you can change "group" or not.
chown -R root:root /usr/share/MyApplicationDirectory
means only user root or someone in group
root (most Linux systems, including Ubuntu, have
a root group).
chown -R root /usr/share/MyApplicationDirectory
in this case group is unchanged.
source
Can't change owner (user or group) of directory which I have all rights on?
Part A:
The operation is not permitted because only the owner and root
(TBOMK).
Part B: The answer is now obvious. Either have user b do it, or
perhaps you will have to bite the bullet and use sudo. If you
don't want to use sudo I assume it is because you don't have root
and will have to get someone else to do it, but those appear to
be the only two solutions.
description
This manual
page documents the GNU version of chown. chown
changes the user and/or group ownership of each given file.
If only an owner (a user name or numeric user ID) is given,
that user is made the owner of each given file, and the
files’ group is not changed. If the owner is followed
by a colon and a group name (or numeric group ID), with no
spaces between them, the group ownership of the files is
changed as well. If a colon but no group name follows the
user name, that user is made the owner of the files and the
group of the files is changed to that user’s login
group. If the colon and group are given, but the owner is
omitted, only the group of the files is changed; in this
case, chown performs the same function as
chgrp. If only a colon is given, or if the entire
operand is empty, neither the owner nor the group is
changed.
options
Change the
owner and/or group of each FILE to OWNER and/or GROUP. With
--reference, change the owner and group
of each FILE to those of RFILE.
-c, --changes
like verbose but report only
when a change is made
-f,
--silent, --quiet
suppress most error
messages
-v,
--verbose
output a diagnostic for every
file processed
--dereference
affect the referent of each
symbolic link (this is the default), rather than the
symbolic link itself
-h,
--no-dereference
affect symbolic links instead
of any referenced file (useful only on systems that can
change the ownership of a symlink)
--from=CURRENT_OWNER:CURRENT_GROUP
change the owner and/or group
of each file only if its current owner and/or group match
those specified here. Either may be omitted, in which case a
match is not required for the omitted attribute
--no-preserve-root
do not treat ’/’
specially (the default)
--preserve-root
fail to operate recursively on
’/’
--reference=RFILE
use RFILE’s owner and
group rather than specifying OWNER:GROUP values
-R,
--recursive
operate on files and
directories recursively
The following
options modify how a hierarchy is traversed when the
-R option is also specified. If more than one
is specified, only the final one takes effect.
-H
if a command line argument is a symbolic link to a
directory, traverse it
-L
traverse every symbolic link to a directory
encountered
-P
do not traverse any symbolic links (default)
--help
display this help and exit
--version
output version information and
exit
Owner is
unchanged if missing. Group is unchanged if missing, but
changed to login group if implied by a ’:’
following a symbolic OWNER. OWNER and GROUP may be numeric
as well as symbolic.
copyright
Copyright © 2012 Free Software Foundation, Inc. License GPLv3+:
GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute
it. There is NO WARRANTY, to the extent permitted by law.
reporting bugs
Report chown bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page:
<http://www.gnu.org/software/coreutils/>
General help using GNU software:
<http://www.gnu.org/gethelp/>
Report chown translation bugs to
<http://translationproject.org/team/>
see also
chown
The full
documentation for chown is maintained as a Texinfo
manual. If the info and chown programs are
properly installed at your site, the command
info
coreutils 'chown invocation'
should give you
access to the complete manual.
author
Written by
David MacKenzie and Jim Meyering.