Planet Collab

🔒
❌ About FreshRSS
There are new available articles, click to refresh the page.
Before yesterdayYour RSS feeds

Linux – Take ownership of directory and files

By italchemy

#1. Add a new user
root@pams1:~$ adduser hugh
adduser: Only root may add a user or group to the system.
root@pams1:~$ sudo adduser hugh
Adding user `hugh’ …
Adding new group `hugh’ (1003) …
Adding new user `hugh’ (1003) with group `hugh’ …
Creating home directory `/home/hugh’ …
Copying files from `/etc/skel’ …
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for hugh
Enter the new value, or press ENTER for the default
Full Name []: Hugh C.
Room Number []: 100
Work Phone []: 02 98765432
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

#2. Add the user to Sudoer group to allow him to run sudo commands
root@pams1:~$ sudo usermod -aG sudo hugh
root@pams1:~$ su – hugh
Password:
To run a command as administrator (user “root”), use “sudo <command>”.
See “man sudo_root” for details.

#3. Check the previlage level by running ‘sudo whoami’
hugh@pams1:~$ sudo whoami
[sudo] password for hugh:
root

#4. To view the groups, runt ‘groups’ command
hugh@pams1:~$ groups
hugh sudo

# Check group membership using ‘groups user_name’
hugh@pams1:~$ groups hugh
hugh : hugh sudo

# Check who belongs to sudo group, sun “grep ‘sudo’ /etc/group” command
hugh@pams1:~$ grep ‘sudo’ /etc/group
sudo:x:27:root,hugh

#5. Optionally, if you want to copy and change the ownership of the directories, you can at this stage.
* brendan is the old user and hugh is the new user. This has to be performed as a root user or after logging in as brendan.
Of course, if hugh is a root user, then he can use sudo to perform this task too.

brendan@pams1:~$ sudo cp -r ./csr1000v /home/hugh/csr1000v
#6. To take ownership of a directory or file run the following commands. You can use this for both directory and files.

#A. to take ownership of a directory only (leave the file ownership as is)
hugh@pams1:~$ sudo chown hugh:hugh csr1000v

hugh@pams1:~$ ls -lh
total 28K
drwxr-xr-x 2 hugh hugh 4.0K Sep 2 10:16 csr1000v

hugh@pams1:~$ ls csr1000v -lh
total 414M
-rw-r–r– 1 brendan brendan 414M Sep 2 10:16 csr1000v-universalk9.16.09.05.SPA.bin
#B. to take ownership of a directory and change the ownership to the user, use -R
hugh@pams1:~$ sudo chown -R hugh:hugh csr1000v
hugh@pams1:~$ ls -lh
total 28K
drwxr-xr-x 2 hugh hugh 4.0K Sep 2 10:16 csr1000v

hugh@pams1:~$ ls csr1000v -lh
total 414M
-rw-r–r– 1 hugh hugh 414M Sep 2 10:16 csr1000v-universalk9.16.09.05.SPA.bin

Linux – Take ownership of directory and files

By italchemy

#1. Add a new user
root@pams1:~$ adduser hugh
adduser: Only root may add a user or group to the system.
root@pams1:~$ sudo adduser hugh
Adding user `hugh’ …
Adding new group `hugh’ (1003) …
Adding new user `hugh’ (1003) with group `hugh’ …
Creating home directory `/home/hugh’ …
Copying files from `/etc/skel’ …
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for hugh
Enter the new value, or press ENTER for the default
Full Name []: Hugh C.
Room Number []: 100
Work Phone []: 02 98765432
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

#2. Add the user to Sudoer group to allow him to run sudo commands
root@pams1:~$ sudo usermod -aG sudo hugh
root@pams1:~$ su – hugh
Password:
To run a command as administrator (user “root”), use “sudo <command>”.
See “man sudo_root” for details.

#3. Check the previlage level by running ‘sudo whoami’
hugh@pams1:~$ sudo whoami
[sudo] password for hugh:
root

#4. To view the groups, runt ‘groups’ command
hugh@pams1:~$ groups
hugh sudo

# Check group membership using ‘groups user_name’
hugh@pams1:~$ groups hugh
hugh : hugh sudo

# Check who belongs to sudo group, sun “grep ‘sudo’ /etc/group” command
hugh@pams1:~$ grep ‘sudo’ /etc/group
sudo:x:27:root,hugh

#5. Optionally, if you want to copy and change the ownership of the directories, you can at this stage.
* brendan is the old user and hugh is the new user. This has to be performed as a root user or after logging in as brendan.
Of course, if hugh is a root user, then he can use sudo to perform this task too.

brendan@pams1:~$ sudo cp -r ./csr1000v /home/hugh/csr1000v
#6. To take ownership of a directory or file run the following commands. You can use this for both directory and files.

#A. to take ownership of a directory only (leave the file ownership as is)
hugh@pams1:~$ sudo chown hugh:hugh csr1000v

hugh@pams1:~$ ls -lh
total 28K
drwxr-xr-x 2 hugh hugh 4.0K Sep 2 10:16 csr1000v

hugh@pams1:~$ ls csr1000v -lh
total 414M
-rw-r–r– 1 brendan brendan 414M Sep 2 10:16 csr1000v-universalk9.16.09.05.SPA.bin
#B. to take ownership of a directory and change the ownership to the user, use -R
hugh@pams1:~$ sudo chown -R hugh:hugh csr1000v
hugh@pams1:~$ ls -lh
total 28K
drwxr-xr-x 2 hugh hugh 4.0K Sep 2 10:16 csr1000v

hugh@pams1:~$ ls csr1000v -lh
total 414M
-rw-r–r– 1 hugh hugh 414M Sep 2 10:16 csr1000v-universalk9.16.09.05.SPA.bin

❌