command in linux Operation systems 1. What are two different ways to determine t
ID: 3829317 • Letter: C
Question
command in linux Operation systems
1. What are two different ways to determine the ownership of the /etc/passwd file? (2 pts)
2. Create a file in your home directory named myfile. What sequence of commands will allow you to transfer ownership of this file to the root user? (2 pts)
3. Who is now listed as the user owner and the group owner for the file myfile?
4. What are two different ways to determine which groups you are a member of? (2 pts)
5. What is the primary group of the sysadmin user?
6. What command would you use to change the sysadmin user’s primary group to the adm group?
7. What command would you use to verify this change took place? What was the GID of this group?
8. Create a directory called spreadsheets in your home directory.
What command would you use to remove read, write, and execute permissions from group and others for the spreadsheets directory using the rwx symbols? (2 pts)
What command can you use to verify this change took place??
9. Using octal permissions, assign the following permissions to the myfile file: -rwxrw-r- -?
10. What command would you use so that all new files created by you have default permissions of: -rw-r- - - - -?
Explanation / Answer
Note: Try the same commands i have done below for questions in your system. Because these are executed in my system and the results may vary from your system. But command wise it would be same.
1. What are two different ways to determine the ownership of the /etc/passwd file? (2 pts)
Ans) Two ways you can determine ownership of the file. Following are the details.
186590cb0725:Chegg bonkv$ ls -l /etc/passwd
-rw-r--r-- 1 root wheel 6393 Sep 29 2016 /etc/passwd
186590cb0725:Chegg bonkv$ stat /etc/passwd
16777220 418444 -rw-r--r-- 1 root wheel 0 6393 "Apr 29 20:14:23 2017" "Sep 29 04:46:14 2016" "Jan 24 04:09:48 2017" "Sep 29 04:46:14 2016" 4096 0 0x20 /etc/passwd
2. Create a file in your home directory named myfile. What sequence of commands will allow you to transfer ownership of this file to the root user? (2 pts)
Ans)
creating a file "myfile" in my home directory:
186590cb0725:~ bonkv$ cat>myfile
the filename is myfile
listing the file contents of myfile:
186590cb0725:~ bonkv$ cat myfile
the filename is myfile
current owner of file is bonkv for the file "myfile":
186590cb0725:~ bonkv$ ls -l myfile
-rw-r--r-- 1 bonkv 1896053708 23 Apr 30 10:07 myfile
using sudo to change the owner to root from bonkv:
186590cb0725:~ bonkv$ sudo chown root myfile
Password:
186590cb0725:~ bonkv$ ls -l myfile
-rw-r--r-- 1 root 1896053708 23 Apr 30 10:07 myfile
3. Who is now listed as the user owner and the group owner for the file myfile?
Ans) for the file "myfile", "root" is the user owner and group owner is "1896053708"
4. What are two different ways to determine which groups you are a member of? (2 pts)
Ans) "id" and "groups" command will tell you which groups you are member of. Below is the usage.
186590cb0725:~ bonkv$ id
uid=2076059800(bonkv) gid=1896053708 groups=1896053708,702(com.apple.sharepoint.group.1),12(everyone),62(netaccounts),80(admin),704(com.apple.sharepoint.group.2),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)
186590cb0725:~ bonkv$ groups bonkv
1896053708 com.apple.sharepoint.group.1 everyone netaccounts admin com.apple.sharepoint.group.2 _appstore _lpadmin _lpoperator _developer com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh
5. What is the primary group of the sysadmin user?
Ans)
Primary group of sysadmin would be mostly sysadmin or sometimes sys. I dont have the sysadmin user in my account. But you can verify the same in /etc/group file by grepping for sysadmim something like below.
> cat /etc/group|grep sysadmin
6. What command would you use to change the sysadmin user’s primary group to the adm group?
Ans) "chgrp" command with sudo permissions can be used to change the group
7. What command would you use to verify this change took place? What was the GID of this group?
Ans) We can use "groups" command to verify the same. For example if you want to see group for a paticular user like admin. you can do like below. You can identify GID of this group using "id" command
>groups admin
You can also identify GID of a particulr group using "id" command
>id admin
In fact "id" command should be able to provide both groups and GID information.
8. Create a directory called spreadsheets in your home directory.
What command would you use to remove read, write, and execute permissions from group and others for the spreadsheets directory using the rwx symbols? (2 pts) What command can you use to verify this change took place??
Ans) The below chmod command would be able to remove read, write and execute permissions for group and others for a given file. Replace your spreadsheet directory in the place of "<filename>"
> chmod go-rwx <filename>
If you want to remove the permissions even inside the spreadsheet directory. Add '-R' option like below
> chmod -R go-rwx <filename>
9. Using octal permissions, assign the following permissions to the myfile file: -rwxrw-r- -?
Ans)
current permissions of the file "myfile":
186590cb0725:~ bonkv$ ls -trlh myfile
-rw------- 1 bonkv 1896053708 23B Apr 30 10:07 myfile
changing permissions using octal code:
186590cb0725:~ bonkv$ chmod 764 myfile
186590cb0725:~ bonkv$ ls -l myfile
-rwxrw-r-- 1 bonkv 1896053708 23 Apr 30 10:07 myfile
For your information Octal codes for read, write and execute permissions are:
read(r) - 4
write(w) - 2
execute(e) -1
10. What command would you use so that all new files created by you have default permissions of: -rw-r- - - - -?
Ans)
We can use "umask" command for this. There are multiple ways of doing this. The simplest one is below.
> umask u=rw,g=r
After this command all files created will have default permission with user having read(r) and write, group will have read-only and others no permissions.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.