Unix Basics File Permissions · What are File Attributes? rwrr The file attributes are represented...
Transcript of Unix Basics File Permissions · What are File Attributes? rwrr The file attributes are represented...
Unix Basics File Permissions
Daniel Lucio
Introduction to Unix
Overview• Where to use it?
• Multiuser Environment
• Related Commands
• What are attributes?
• File Types
• Permission Types
• Changing file modes
• What is umask?
Introduction to Unix
Where to use it?
• Login to a Unix system like ’kraken’ or any other NICS/UT/XSEDE resource.
• Download and boot from a Linux LiveCD either from a CD/DVD or USB drive.
• http://www.puppylinux.com/
• http://www.knopper.net/knoppix/index-en.html
• http://www.ubuntu.com/
Introduction to Unix
Where to use it?
• Install Cygwin: a collection of tools which provide a Linux look and feel environment for Windows.
• http://cygwin.com/index.html
• https://newton.utk.edu/bin/view/Main/Workshop0InstallingCygwin
• Online terminal emulator
• http://bellard.org/jslinux/
• http://simpleshell.com/
Introduction to Unix
MultiUser EnvironmentUnix is a multitasking and multiuser Operating System.
Introduction to UnixIntroduction to Unix
MultiUser Related Commandsid! ! ! Display user identity
chmod!! Change a file’s mode
umask!! Set the default file permission
chown!! Change a file’s owner
chgrp!! Change a file’s group ownership
su! ! ! Run a shell as another user
sudo!! ! Execute a command as another user
passwd!! Change a user’s password
Introduction to Unix
What are File Attributes?
-‐rw-‐r-‐-‐r-‐-‐
The file attributes are represented by ten characters. The first character represents the file type and the other nine
represent represent the Read, Write and execute permissions for the User, Group owner and Others.
File Type User Group Others
Introduction to UnixIntroduction to Unix
File Types
-! ! ! Regular file
d! ! Directory
l! ! ! Symbolic link
c! ! ! Character special file. Refers to a device that
handles data as a stream of bytes such as a
terminal or modem.
b! ! ! Block special file. Refers to a device that
handles data in blocks such as a hard drive.
Introduction to UnixIntroduction to Unix
Permission Types
Attribute Files Directory
r Allows file to opened and read
Allows to list contents of a directory if X also set
w Allows to write to file
Allows to create, rename and delete files if X is also set.
x Allows the file to be treated as an executable Allows to enter a directory
Introduction to UnixIntroduction to Unix
Changing file modes
Oct Binary File Mode0 0 -‐ -‐ -‐
1 1 -‐ -‐ x
2 10 -‐ w -‐
3 11 -‐ w x
4 100 r -‐ -‐
5 101 r -‐ x
6 110 r w -‐
7 111 r w x
Use the ‘chmod’ command to change or set the file or directory permissions. This commands allows two ways to indicate the permissions:
octal and symbolic representation.
Symbol Meaning
u User or file/directory owner
g Group owner
o Others
a All:u+g+o
Introduction to Unix
‘chmod’ exampleschmod 600 foo.txt Only owner can read and write
chmod 755 program Owner can R,W,X, and members of Group and Others can Read and eXecute too but not write
chmod u+x foo.txt Add execute permission to owner
chmod u+rw,go= foo.txt Only owner can read and write
chmod a+rx,go-‐w program Owner can R,W,X, and members of Group and Others can Read and eXecute too but not write
Introduction to UnixIntroduction to Unix
Special Types
Attribute Octal Symbol Meaning
setuid 4000 u+s
Executable files with this bit set will run with effective uid set to the uid of the file owner. Directories with the set-user-id bit set will force all files and sub-directories created in them to be owned by the directory owner and not by the uid of the creating process
setgid 2000 g+s
If set on a directory, newly created files in that directory will inherit the group ownership of the directory. Useful when members of a common group need access to files in same directory
sticky bit 1000 +t
When applied to a directory, it prevents users from deleting or renaming files unless is the owner. Used to control access to a shared
directory
Introduction to UnixIntroduction to Unix
What is ‘umask’?The ‘umask’ command sets the default file permissions
given to a file when created.
user086@sshell ~ $ umask !0022!user086@sshell ~ $ touch foo.txt!user086@sshell ~ $ ls -l foo.txt!-rw-r--r-- 1 user086 webusers 0 Nov 19 17:27 foo.txt !user086@sshell ~ $ umask 0000!user086@sshell ~ $ touch hello.txt!user086@sshell ~ $ ls -l hello.txt!-rw-rw-rw- 1 user086 webusers 0 Nov 19 17:27 hello.txt !user086@sshell ~ $ umask 0066!user086@sshell ~ $ touch world.txt!user086@sshell ~ $ ls -l world.txt!-rw------- 1 user086 webusers 0 Nov 19 17:28 world.txt
Note: You can only use octal format with ‘umask’
Introduction to Unix
The ‘chown’ Command
$ chown [owner][:][group] file . . .
Example:/var/root # touch foo.txt !/var/root # ls -l !total 0 !-rw-r--r-- 1 root root 0 Nov 19 17:57 foo.txt !/var/root # chown operator foo.txt !/var/root # ls -l !total 0 !-rw-r--r-- 1 operator root 0 Nov 19 17:58 foo.txt!/var/root # chown operator:users foo.txt !/var/root # ls -l !total 0 !-rw-r--r-- 1 operator users 0 Nov 19 17:58 foo.txt
The chown command is used to change the owner and group owner of a file or a directory.
Introduction to Unix
More informationhttp://www.gnu.org/
http://www.linux.org/
Unix man pages!http://www.ubuntu.com/
http://linuxcommand.org