Unix Accounts - PowerPoint PPT Presentation

1 / 62
About This Presentation
Title:

Unix Accounts

Description:

Computer Systems Architeture and Administration ... Unix Accounts – PowerPoint PPT presentation

Number of Views:122
Avg rating:3.0/5.0
Slides: 63
Provided by: diti7
Category:

less

Transcript and Presenter's Notes

Title: Unix Accounts


1
Unix Accounts
2
Unix Accounts
  • To access a Unix system you need to have an
    account.
  • Unix account includes
  • username and password
  • userid and groupid
  • home directory
  • shell

23/07/2016
2
3
username
  • A username is (typically) a sequence of
    alphanumeric characters of length no more than 8.
  • username the primary identifying attribute of
    your account.
  • username is (usually) used as an email address
  • the name of your home directory is usually
    related to your username.

23/07/2016
3
4
password
  • a password is a secret string that only the user
    knows (not even the system knows!)
  • When you enter your password the system encrypts
    it and compares to a stored string.
  • passwords are (usually) no more than 8 characters
    long.
  • It's a good idea to include numbers and/or
    special characters (don't use an english word!)

23/07/2016
4
5
userid
  • a userid is a number (an integer) that identifies
    a Unix account. Each userid is unique.
  • It's easier (and more efficient) for the system
    to use a number than a string like the username.
  • You don't need to know your userid!

23/07/2016
5
6
Unix Groups and groupid
  • Unix includes the notion of a "group" of users.
  • A Unix group can share files and active
    processes.
  • Each account is assigned a "primary" group.
  • The groupid is a number that corresponds to this
    primary group.
  • A single account can belong to many groups (but
    has only one primary group).

23/07/2016
6
7
Home Directory
  • A home directory is a place in the file system
    where the account files are stored.
  • A directory is like a Windows folder.
  • Many unix commands and applications make use of
    the account home directory (as a place to look
    for customization files).

23/07/2016
7
8
Shell
  • A Shell is a unix program that provides an
    interactive session - a text-based user
    interface.
  • When you log in to a Unix system the program you
    initially interact with is your shell.
  • There are a number of popular shells that are
    available.

23/07/2016
8
9
Logging In
  • To log in to a Unix machine you can either
  • sit at the console (the computer itself)
  • access via the net (using putty, telnet, rsh,
    ssh, kermit, or some other remote access client).
  • The system prompts you for your username and
    password.
  • Usernames and passwords are case sensitive!

23/07/2016
9
10
Session Startup
  • Once you log in, your shell will be started and
    it will display a prompt.
  • When the shell is started it looks in your home
    directory for some customization files.
  • You can change the shell prompt and a bunch of
    other things by creating customization files
    (more on this later)

23/07/2016
10
11
Your Home Directory
  • Every Unix process has a notion of the current
    working directory.
  • You shell (which is a process) starts with the
    current working directory set to your home
    directory.
  • A process is an instance of a program that is
    currently running.

23/07/2016
11
12
Interacting with the Shell
  • The shell prints a prompt and waits for you to
    type in a command.
  • The shell can deal with a couple of types of
    commands
  • shell internals - commands that the shell handles
    directly.
  • External programs - the shell runs a program for
    you.

23/07/2016
12
13
UNIX commands and the filesystem
14
Some Simple Commands
  • Here are some simple commands to get you started
  • ls lists file names (like DOS dir command).
  • who lists users currently logged in.
  • date shows the current time and date.
  • pwd print working directory
  • To shutdown a server (sys admin only)
  • Init 0

23/07/2016
14
15
Files and File Names
  • A file is a basic unit of storage (usually
    storage on a disk).
  • Every file has a name.
  • Unix file names can contain any characters
    (although some make it difficult to access the
    file).
  • Unix file names can be long!
  • how long depends on your specific flavor of Unix

23/07/2016
15
16
File Contents
  • Each file can hold some raw data.
  • Unix does not impose any structure on files
  • files can hold any sequence of bytes.
  • Many programs interpret the contents of a file as
    having some special structure
  • text file, sequence of integers, database
    records, etc.

23/07/2016
16
17
Directories
  • A directory is a special kind of file - Unix uses
    a directory to hold information about other
    files.
  • We often think of a directory as a container that
    holds other files (or directories).
  • On Windows, a directory is the same idea as a
    folder.

23/07/2016
17
18
The Filesystem
/
ls
who
netprog
unix
X
23/07/2016
18
19
The Filesystem
/
ls
who
netprog
unix
X
Syllabus
/users/bob/unix/Syllabus
23/07/2016
19
20
Absolute Pathnames
  • The pathnames described in the previous slides
    start at the root.
  • These pathnames are called "absolute pathnames".
  • We can also talk about the pathname of a file
    relative to a directory.

23/07/2016
20
21
Relative Pathnames
  • If we are in the directory /users/bob, the
    relative pathname of the file Syllabus is
  • unix/Syllabus
  • Most unix commands deal with pathnames!
  • We will usually use relative pathnames when
    specifying files.

23/07/2016
21
22
Example The ls command
  • Exercise login to a unix account and type the
    command "ls".
  • The names of the files are shown (displayed) as
    relative pathnames.
  • Try this
  • ls /usr
  • ls should display the name of each file in the
    directory /usr.

23/07/2016
22
23
Disk vs. Filesystem
  • The entire hierarchy can actually include many
    disk drives.
  • some directories can be on other computers

/
bob
fred
23/07/2016
23
24
The current directory and parent directory
  • There is a special relative pathname for the
    current directory
  • .
  • There is a special relative pathname for the
    parent directory
  • ..

23/07/2016
24
25
The ls command
  • The ls command displays the names of some files.
  • If you give it the name of a directory as a
    command line parameter it will list all the files
    in the named directory.

23/07/2016
25
26
Some things to try
  • ls list files in current directory
  • ls / list files in the root directory
  • ls . list files in the current directory
  • ls .. list files in the parent directory
  • ls /usr list files in the directory /usr

23/07/2016
26
27
Command Line Options
  • We can modify the output format of the ls program
    with a command line option.
  • The ls command support a bunch of options
  • l long format (include file times, owner and
    permissions)
  • a all (shows hidden files as well as regular
    files)
  • F include special char to indicate file types.
  • hidden files have names that start with "."

23/07/2016
27
28
ls command line options
  • To use a command line option precede the option
    letter with a minus
  • ls -a or ls -l
  • You can use 2 or more options at the same time
    like this
  • ls -al

23/07/2016
28
29
General ls command line
  • The general form for the ls command is
  • ls options names
  • The options must come first!
  • You can mix any options with any names.
  • An example
  • ls -al /usr/bin

23/07/2016
29
30
ls options names
  • The brackets around options and names in the
    general form of the ls command means that
    something is optional.
  • We will see the general form of many commands
    described in this manner.
  • Some commands have required parameters.

23/07/2016
30
31
Many names
  • You can give the ls command many names
  • ls /usr /etc
  • ls -l /usr/bin /tmp /etc

23/07/2016
31
32
Moving Around in the Filesystem
  • There cd command can change the current working
    directory
  • cd change directory
  • The general form is
  • cd directoryname

23/07/2016
32
33
cd
  • With no parameter, the cd command changes the
    current directory to your home directory.
  • You can also give cd a relative or absolute
    pathname
  • cd /usr
  • cd ..

23/07/2016
33
34
Some more commands and command line options
  • ls -R will list everything in a directory and in
    all the subdirectories recursively (the entire
    hierarchy).
  • you might want to know that Ctrl-C will cancel a
    command (stop the command)!
  • pwd print working directory
  • df shows what disk holds a directory.

23/07/2016
34
35
Copying Files
  • The cp command copies files
  • cp options source dest
  • The source is the name of the file you want to
    copy.
  • dest is the name of the new file.
  • source and dest can be relative or absolute.

23/07/2016
35
36
Another form of cp
  • If you specify a dest that is a directory, cp
    will put a copy of the source in the directory.
  • The filename will be the same as the filename of
    the source file.
  • cp options source destdir

23/07/2016
36
37
Yet another form of cp
  • If you specify more than two names, cp assumes
    you are using this form.
  • cp options source... destdir
  • In this case cp will copy multiple files to
    destdir.
  • source... means at least one name (could be more
    than one)

23/07/2016
37
38
Deleting (removing) Files
  • The rm command deletes files
  • rm options names...
  • rm stands for "remove".
  • You can remove many files at once
  • rm foo /tmp/blah /users/john/course

23/07/2016
38
39
rm Exercises
  • Try to delete /etc/passwd
  • Try to delete a directory
  • Look at the man page for rm
  • man rm

23/07/2016
39
40
File attributes
  • Every file has some attributes
  • Access Times
  • when the file was created
  • when the file was last changed
  • when the file was last read
  • Size
  • Owners (user and group)
  • Permissions

23/07/2016
40
41
File Time Attributes
  • Time Attributes
  • when the file was last changed ls -l
  • when the file was created ls -lc
  • when the file was last read (accessed) ls -ul
  • actually its the time the file status last
    changed.

23/07/2016
41
42
File Owners
  • Each file is owned by a user.
  • You can find out the username of the file's owner
    with the "-l" option to ls,
  • Each file is also owned by a Unix group.
  • ls -l also shows the group that owns the file.

23/07/2016
42
43
File Permissions
  • Each file has a set of permissions that control
    who can mess with the file.
  • There are three kinds of permissions
  • read abbreviated r
  • write abbreviated w
  • execute abbreviated x
  • There are separate permissions for
  • the file owner, group owner and everyone else.

23/07/2016
43
44
ls -l
  • gt ls -l foo
  • -rw-rw---- 1 bob grads 13 Jan 10 2305 foo

size
permissions
name
owner
group
time
23/07/2016
44
45
ls -l and permissions
  • -rwxrwxrwx
  • Owner Group Others

Type of file - means plain file d means
directory
23/07/2016
45
46
rwx
  • Files
  • r - allowed to read.
  • w - allowed to write.
  • x - allowed to execute
  • Directories
  • r - allowed to see the names of the file.
  • w - allowed to add and remove files.
  • x - allowed to enter the directory

23/07/2016
46
47
Changing Permissions
  • The chmod command changes the permissions
    associated with a file or directory.
  • There are a number of forms of chmod, this is the
    simplest
  • chmod mode file

23/07/2016
47
48
chmod mode file
  • Mode has the following form
  • ugoa-rwx
  • uuser ggroup oother aall
  • add permission - remove permission
    set permission
  • The form is really more complicated, but this
    simple version will do enough for now.

23/07/2016
48
49
chmod examples
  • gt ls -al foo
  • rwxrwx--x 1 hollingd grads
  • gt chmod g-wx foo
  • gt ls -al foo
  • -rwxrw---- 1 hollingd grads
  • gtchmod u-r .
  • gtls -al foo
  • ls . Permission denied

23/07/2016
49
50
Other filesystem and file commands
  • mkdir make directory
  • rmdir remove directory
  • touch change file timestamp (can also create a
    blank file)
  • cat concatenate files and print out to terminal.

23/07/2016
50
51
Some commands worth knowing
  • finger user name
  • who and whoami
  • users
  • Lists who is logged in
  • whereis command name
  • Checks your path
  • find
  • Find path name file name
  • Find / -name whereis
  • Find / -name wh

23/07/2016
51
52
Some commands worth knowing
  • history
  • !number in history
  • head display top few lines of a file
  • more operates like man (and supports searching)

23/07/2016
52
53
Job control
  • command
  • Run the command in the background
  • For a running program, ctrl-z stops it (but
    doesnt kill it)
  • fg brings a background job into the foreground
  • Jobs list the processes running (stopped or not)
    from the current shell.
  • bg put a stopped job to run in the background
  • job number bring a stopped job back to the
    foreground
  • Kill job number kills that job

23/07/2016
53
54
vi
  • Remember there are two modes
  • insert and command
  • ESC will always get you back to command

23/07/2016
54
55
Basic vi commands
  • a - Append
  • A Append at the end of the current line
  • i Insert before the current character
  • I insert at the start of the current line
  • r Replace
  • replace one character under the cursor. Specify
    count to replace a number of characters
  • u - undo the last change to the file. Typing u
    again will re-do the change.
  • x - delete character under the cursor. The
    characters will be deleted after the cursor. 5x
    will delete 5 characters

23/07/2016
55
56
Navigation
  • h move the cursor to the left one character
    position.
  • j move the cursor down one line.
  • k move the cursor up one line.
  • l move the cursor to the right one character
    position.

23/07/2016
56
57
More navigation
  • Move to the beginning of the line.
  • Move to the end of the line.
  • w
  • Move to the end of the word.
  • (
  • Move to the beginning of the sentence.
  • )
  • Move to the end of the sentence
  • Move to end of paragraph (defined by a blank
    line)
  • Move to start of paragraph
  • Every command can be repeated by putting a number
    before/after the command
  • 5, 4, 5w,

23/07/2016
57
58
Cutting, Pasting and searching
  • Cut with either delete command or yank (y or Y)
    command
  • Paste with
  • P paste before current position
  • p past after current position
  • Search with
  • /search pattern search from this point on
  • Repeat search with / of n
  • Search pattern is a regular expression
  • /Brley, /Br0-9, /BrR

23/07/2016
58
59
Variations on delete commands
  • d
  • deletes from current cursor position to the
    beginning of the line.
  • d
  • deletes from current cursor position to the end
    of the line.
  • dw
  • deletes from current cursor position to the end
    of the word.
  • dd
  • deletes a line from current cursor position
    downwards.
  • d
  • deletes to end of paragraph.
  • d
  • deletes to start of paragraph.
  • Every command can be repeated by putting a number
    before/after the command
  • 3dd, 5dw, 4d, d5w,
  • Works with yank (y/Y) as well

23/07/2016
59
60
Substituting
  • s/pattern/to_pattern/options
  • s/Ronan/Robert
  • Find first occasion of Ronan and replace with
    Robert
  • s/Ronan/Robert/g
  • Find every occasion of Ronan and replace with
    Robert

23/07/2016
60
61
Open, save, quit
  • vi filename1 filename2
  • n will move to the next file you want to edit
  • w write the file
  • q - quit vi, assumes no changes since last save
  • q! quit and lose changes
  • e - close the current file and open another
  • e! as e but lose changes

23/07/2016
61
62
Some options
  • set all
  • Lists all the options
  • set tabstopx
  • Set the number of spaces for each tab
  • set number
  • Show line numbers
  • set nonumber
  • Hide line numbers

23/07/2016
62
Write a Comment
User Comments (0)
About PowerShow.com