Week 8 - Shell Scripts Part 2 Flashcards

(33 cards)

1
Q

Loops

A

Perform a set of commands repeatedly

Looping statements:
while statement
- interpreter continues executing
the code in the while loop portion of the script as long as the condition is true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The while loop

A

– Repeats commands between
do and done statements
– As long as the tested condition is
true
* When the command after the
while statement returns an exit status code greater than 0
– while statement fails
– Program executes commands after
done statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Basic Arithmetic Expression

A

Arithmetic expression should be place inside
double parenthesis: (( expression ))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The for Loop

A
  • Repeats the commands between
    do and done a specified number of times

– Each time the script carries out the commands in the loop, a new value is given to a variable

– Assign this value in the command with positional parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Shell scripts loops used

A

While and For loops are used
Loops are used to repeat actions on different variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Viewing file permissions command

A

> ls -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Permissions User

A

The file owner

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Permissions Group

A

A group of users; users are divided into groups to facilitate administrative tasks.

  • Each user assigned to a primary group e.g. “users”

– Users can be members of other groups ( secondary groups )

– Each file is owned by a user and a group

– If you create a file, it is owned by
you and your primary group

– Anyone who is a member of that group (primary or secondary), has file permissions specified by that files group permission.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Permissions Other

A

Everyone else on Linux System

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Linux file permissions

A

Mechanism to provide protection to OS
– Users don’t misuse file system resources
– Permission protects the entities of the file system so users cannot misuse entities owned by another user
* Permissions specify who can access a file and the type of access.
– File and Directory owned by a user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Read, Write and Excecute

A

Functions of these permissions differ, depending on whether they’re applied to files or directories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

r (Read)

A

Gives users permission to open a file and view its contents

Allows users to list a directory’s contents with commands such as ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

w (Write)

A

Gives users permission to open and file and edit its contents

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

w (Write)

A

Gives users permission to open and file and edit its contents

Allows users to add or remove files and subdirectories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

x (Execute)

A

Allows users to run the file (as long as it is a program or a script)

Allows users to switch to directory with cd command to read a directory’s contents and add/remove files and subdirectories, you must have execute permission

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Example Read, Write, Execute

A

-rw r– r– 1 alex users 0 2012-04-11 09:20 file1

  • User category of permissions is set to rw
    *Hyphen (–) represents no permission
    *Read, write, not execute
  • Group category is set to r
    *Group has read permission but not write and execute permissions
  • Other category is set to r
  • Every user on the system has read permission but not write or execute
17
Q

Permission commands chmod

A

chmod (change mode) command
changes permissions on files and directories

syntax:
chmod permissions file/directory

Permissions argument
* Information used to change permissions

File/directory argument
* Specifies the file or directory you want to change

18
Q

Symbolic notation

A

Uses criteria such as categories and operators to change file permissions
Example: chmod o-wx file4

u (user) + add to existing permissions
g (group) - remove from existing permissions
o (other) = assign absolute permissions
a (all) one of the preceding operators

o-wx = other remove from existing permissions write and execute

19
Q

Numeric Notation

A

Uses numbers from 0 to 7 to represent file permissions
Example: `chmod 774 file1’

— 0
–x 1
-w- 2
-wx 3
r– 4
r-x 5
rw- 6
rwx 7

20
Q

Managing users

A

Authentication
– Process of verifying someone’s identity by checking his or her username and password against a central user database

  • Linux user database consists of two configuration files:
    /etc/passwd
    /etc/shadow
    User account information is stored in thee 2 database configuration files.
21
Q

The /etc/passwd File

A

Contains user account information

Any user can read it

Each entry has seven fields separated by colons

22
Q

The /etc/shadow File

A

Configuration file containing passwords and password expiration information

For all user accounts

Can be read only by the root user

Explanation of fields:
– Username

– Encrypted password

– Last password change - number of days since January 1, 1970 that the password was last changed

– Minimum number of days before the password can be changed

– Expiration number of days before the password must be changed

  • Warning——number number of days remaining until the of days remaining until the password must be changed

– Disabled——number number of days after a password has of days after a password has expired until the user account is disabled

  • Disabled date——number number of days since January 1, of days since January 1, 1970 that the account has been disabled
23
Q

User account information

A

User information stored in two configuration files:
– /etc / useradd
– /etc login.defs
* Used to store default values when user is created
* Files contain:
–User’s PATH variable
–Password expiration information
–Default primary group
–Location of the home directory

24
Q

Creating user accounts

A

useradd command
– Create user accounts
– Update default information for new users
– E.g useradd user1

After creating a user, a password must be assigned

New user who doesn’t have a password yet:

user1:user1:!!:14745:0:99999:

! character in the encrypted password field means no password has been set for this user

Only the root user can set passwords for new users

passwd command
– Set a password for user1:
sudo passwd user1: sudo passwd user1

25
passwd command
Enter a new password and then enter it again to confirm
26
Modifying user accounts
usermod command – Change user account information – Only the root user can issue this command For a currently logged in user, cannot change: – Name – UID – Home directory
27
Modifying user accounts
chage command Only root user can issue Modify information Number of days between allowed and required password changes Expiration date Warning information chage command used without options - Interactive mode
28
Deleting user accounts
userdel command – Delete user accounts – Remove all entries from user database files – Doesn’t remove the user’s home directory - r option – Remove user’s home directory * When a user is deleted – All files he or she owned are then owned by the UID – If new user created with same UID, new user owns files
29
Managing groups
Groups – Helpful for streamlining the process of designating which users can perform certain tasks * Every user is a member of at least one group –Called the primary group * Root user can assign an unlimited number of additional groups – Called secondary groups * /etc /group – Group database configuration file
30
id command
– View all the groups you belong to and their corresponding GIDs gid: primary group of user * All other groups are secondary groups and are separated by commas
31
The /etc/group File
Configuration file that stores group information * Can be read by everyone on the system
32
Creating groups
groupadd command – Add a group account – Only the root user has permission to use this command newgrp command – Change a user’s primary group temporarily – Stays in effect until the user logs out - Opens a new instance of the BASH shell – Changes the user’s primary group from users to projects
33
Modifying groups
groupmod command - modify existing groups - only the root user has permission to use this command