[go: up one dir, main page]

0% found this document useful (0 votes)
23 views73 pages

Linux Unit II

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views73 pages

Linux Unit II

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 73

UNIT II

 GAINING ACCESS- USING THE ROOT


 ACCOUNT EXPLORING ADMINISTRATIVE COMMANDS
CONFIGURATION FILES, AND LOG FILES USING OTHER
ADMINISTRATIVE ACCOUNTS
 USING SHELL VARIABLES, EXPANDING ARITHMETIC
EXPRESSIONS EXPANDING VARIABLES
 GETTING INFORMATION ABOUT COMMANDS AND HELP-
MANAGING USER ACCOUNTS IN UBUNTU- USER
MANAGEMENT
 MOVING AROUND THE FILESYSTEM UBUNTU- FILE
MANAGEMENT
 WORKING WITH TEXT FILES IN UBUNTU
13. WORKING WITH
SHELL IN UBUNTU
Content:
• About Shells and Terminal Windows
• Gaining Access
• Using Shell Variables
• Getting Information about Commands and help
About Shells and Terminal Windows

Using the shell prompt

The default prompt for a regular user is simply a dollar sign:

The default prompt for the root user is a pound sign (also called a number sign
or a hash tag):

#
About Shells and Terminal Windows

Using a Terminal window

Most Linux distributions make it easy for you to get to a shell from the GUI.
Here are two common ways to launch a Terminal window from a Linux
desktop:

• In the context menu that appears, if you see Open in Terminal, Shells, New
Terminal, Terminal Window, Xterm.

• Many Linux desktops include a panel at the top or bottom of the screen
from which you can launch applications.
About Shells and Terminal Windows

Using virtual consoles

• The GUI is typically located on one of the first two virtual consoles, and the
other six virtual consoles are typically text-based virtual consoles.

• You can switch between virtual consoles by holding the Ctrl and Alt keys and
pressing a function key between F1 and F6.

• You can return to the GUI (if one is running) by pressing Ctrl+Alt+F1. On some
systems, the GUI may run on a different virtual console.

• Try it right now. Hold down the Ctrl+Alt keys and press F3. You should see a
plain-text login prompt. Log in using your username and password.
Gaining Access

Becoming root from the shell (su command)

Use the su command

$ su
Password: ******
#
Gaining Access

Running Commands with Sudo

To enable full sudo access for the user user01, you could create /etc/sudoers.d/user01
with the following content:

user01 ALL=(ALL) ALL


Gaining Access

• Environment variables are variables that are exported to any new shells opened
from the current shell.

• Type env to see environment variables.

You can refer to the value of any of those variables by preceding it with a dollar sign
($) and placing it anywhere on a command line.

For example:

$ echo $USER
Chris

This command prints the value of the USER variable, which holds your username
(chris). Substitute any other value for USER to print its value instead.
Shell Variables

Creating and using aliases

• Using the alias command, you can effectively create a shortcut to any
command and options that you want to run later.

• You can add and list aliases with the alias command.

Consider the following example of using alias from a bash shell:

$ alias p='pwd ; ls –CF'


$ alias rm='rm -i'
Getting Information about commands

Help:

• Use the help command. Some commands are built into the shell, so they do not
appear in a directory.

• The help command lists those commands and shows options available with each
of them.

• Use --help with the command. Many commands include a --help option that you
can use to get information about how the command is used.

Man:
Man pages are the most common means of getting information about
commands as well as other basic components of a Linux system.

$ man passwd
14.MANAGING USER
ACCOUNTS IN UBUNTU
Content:
• User Management
• Group Management
User Management
Creating User Accounts

Creating users in Gnome (GUI) is provide to create a normal user by


using the graphical tool, The user creation graphical tools are available in
Graphical setting.
User Management

Click add user


User Management

Type username and password


User Management

Adding users with useradd

• The useradd username command creates a new user named username.

• The useradd --help command displays the basic options that can be used
to override the defaults.

• Some defaults, such as the range of valid UID numbers and default
password aging rules, are read from the /etc/login.defs file.

• The useradd command determines the default values for new accounts by
reading the /etc/login.defs and /etc/default/useradd files.
User Management

login.defs is different on different Linux systems, the following is an example


containing many of the settings that you might find in a login.defs file:

UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 200
SYS_UID_MAX 999
GID_MIN 1000
GID_MAX 60000
SYS_GID_MIN 201
SYS_GID_MAX 999
CREATE_HOME yes
User Management

Modifying users with usermod

The usermod command provides a simple and straightforward method for


changing account parameters.

The following are examples of the usermod command:

# usermod -s /bin/csh chris


# usermod -Ga sales,marketing, chris
User Management

Deleting users with userdel

• The userdel username command removes the details of username


from /etc/passwd, but leaves the user's home directory intact.

• The userdel -r username command removes the details of username


from /etc/passwd and also deletes the user's home directory.
Group Management

Understanding Group Accounts

• A group is a collection of users that need to share access to files and other system
resources.

• Groups can be used to grant access to files to a set of users instead of just a single user.

• Like users, groups have group names to make them easier to work with.
Group Management

Understanding Group Accounts

• Internally, the system distinguishes groups by the unique identification number assigned
to them, the group ID or GID.

• The mapping of group names to GIDs is defined in databases of group account


information.

• By default, systems use the /etc/group file to store information about local groups.
Group Management

• Each line in the /etc/group file contains information about one group.

• Each group entry is divided into four colon-separated fields.

Here is an example of a line from /etc/group:

group011: x2: 100003: user01,user02,user034

• Group name for this group (group01).


• Obsolete group password field. This field should always be x.
• The GID number for this group (10000).
• A list of users who are members of this group
Group Management

Creating group accounts

The groupadd command creates groups.

Without options the groupadd command uses the next available GID from the
range specified in the /etc/login.defs file while creating the groups.

The -g option specifies a particular GID for the group to use.

[user01@host ~]$ sudo groupadd -g 10000 group01


[user01@host ~]$ tail /etc/group
...output omitted...
group01:x:10000:
Group Management

Creating group accounts

The -r option creates a system group using a GID from the range of valid system
GIDs listed in the /etc/login.defs file.

To change a group later, use the groupmod command, as in the following example:

# groupmod -g 330 jokers


# groupmod -n jacks jokers
15. MOVING AROUND
THE FILESYSTEM
UBUNTU
Content:
• File Management
• Permission Management
• Access Control Lists
File Management

Using Basic File system Commands


BASIC SHELL MANAGEMENT

1. Listing commands:

1.1. Using ls commands to list all files and directories in current directory.
BASIC SHELL MANAGEMENT

1. Listing commands:

1.2. Using ls –a command to list hidden files also.


BASIC SHELL MANAGEMENT

1.3. Using ls –l to long listing the files and directory information in a current directory
BASIC SHELL MANAGEMENT

1.4. Using ls –la for long listing the hidden files also.
BASIC SHELL MANAGEMENT

1.5. Using the ls –sh & ls –sha to listing the files and directory with size.
BASIC SHELL MANAGEMENT

1.6. To classify the files and directories, you can use ls –aF command
BASIC SHELL MANAGEMENT

2. Changing Directory:

2.1. Using cd command and followed by the directory path to changing the working
directory and you can verify by using the pwd command to check the present working
directory.
BASIC SHELL MANAGEMENT

2. Changing Directory:

2.2. Using cd command alone to get back to the user’s home directory.
BASIC SHELL MANAGEMENT

2.3. Using cd – to change the directory to previous working directory


BASIC SHELL MANAGEMENT

2.4. Using cd.. to change the directory to previous directory


BASIC SHELL MANAGEMENT

3. System related commands

3.1. Use the date command to display the current time and date.

3.2. Use the file command to determine its file type.


BASIC SHELL MANAGEMENT

3. System related commands

3.3. Use lsblk command to check the hard disk and partition informations
BASIC SHELL MANAGEMENT

3.4. Use uptime to check the machine load average.


BASIC SHELL MANAGEMENT

3.5. Use cal, cal -3, cal –y (year) to list all the information of calendar in monthly
BASIC SHELL MANAGEMENT

3.6. Use bc command is for opening the basic calculator (use ctrl+c or ctrl+d to close)
BASIC SHELL MANAGEMENT

3.7. Use free to list the memory information


Permission Management

Understanding File Permissions and Ownership


Permission Management

1. Managing file permission using Symbolic method

1.1. Create a file “perm” and adding executes(x) permission for user section to the file ‘perm’
Permission Management

1. Managing file permission using Symbolic method

1.2. Adding write (w) permission for group section and executes (x) permission for
other section to the file ‘perm’
Permission Management

1.3. Remove the execute (x) permission for user, write (w) permission for group and
execute (x) for other to the file ‘perm’
Permission Management

1.4. Changing the permission by using exactly (=) for the user section to the file ‘perm’
Permission Management

1.5. Adding write (w)permission to all the section for the file ‘perm’
Permission Management

1.6. Modifying the permission read, write, executes by using exactly (=) for the all section
to the file ‘perm’
Permission Management

2. Managing file permission using Numeric method


2.1. Create a directory ‘dir1’ and modifying the permission by ‘754’

2.2. Modifying the directory by full permission


Permission Management

3. Changing ownership of the file


3.1. Creating a directory ‘dir2’ and change the directory ownership (as root user)
Permission Management

3.2. Changing the group ownership permission for the directory ‘dir2’

3.3. Using ‘chown’ command to change both ownership and group ownership
14. WORKING WITH
TEXT FILES IN UBUNTU
Content:
• File Manipulation
File Manipulation

Editing Files with vim and vi

• If you are using a GNOME desktop, you can run gedit.

• The vi editor is difficult to learn at first, but after you know it, you never
have to use a mouse or a function key.

• You can edit and move around quickly and efficiently within files just by
using the keyboard.
File Manipulation

Starting with vi

Most often, you start vi to open a particular file. For example, to open a file called
/tmp/test, enter the following command:

$ vi /tmp/test

If this is a new file, you should see something similar to the following:

~
~
~
~
~
"/tmp/test" [New File]
File Manipulation

 a: The add command. With this command, you can input text that
starts to the right of the cursor.

 A: The add at end command. With this command, you can input text
starting at the end of the current line.

 i: The insert command. With this command, you can input text that
starts to the left of the cursor.
File Manipulation

 I: The insert at beginning command. With this command, you can input
text that starts at the beginning of the current line.

 o: The open below command. This command opens a line below the
current line and puts you in insert mode.

 O: The open above command. This command opens a line above the
current line and puts you in insert mode.
File Manipulation

Moving around in the text

 Arrow keys: Move the cursor up, down, left, or right in the file one character
at a time. To move left and right.

 w: Moves the cursor to the beginning of the next word


 W: Moves the cursor to the beginning of the next word
 b: Moves the cursor to the beginning of the previous word (delimited by
spaces, tabs, or punctuation).
 B: Moves the cursor to the beginning of the previous word (delimited by
spaces or tabs).
File Manipulation

Moving around in the text

 0 (zero): Moves the cursor to the beginning of the current line.

 $: Moves the cursor to the end of the current line.

 H: Moves the cursor to the upper-left corner of the screen (first line on the
screen).

 M: Moves the cursor to the first character of the middle line on the screen.

 L: Moves the cursor to the lower-left corner of the screen (last line on the
screen).
EDITING FILES USING EDITORS

1. Edit files with cat


1.1. Creating a file and edit using cat using redirection (using ctrl+c or ctrl+d to
close)

1.2. Using double redirection to update content in a file by cat command


EDITING FILES USING EDITORS
2. Editing files with vim.
2.1 Creating a file and editing using the vim editor.

2.2. Press ‘i’ or ‘insert’ to go insert mode from command mode


EDITING FILES USING EDITORS

2.3. In insert mode all the keys are input, just insert some message
EDITING FILES USING EDITORS

2.4. Give ‘esc’ to get back to command mode


EDITING FILES USING EDITORS
2.5. In command mode use ‘yy’ for copy a single line or (n)yy for
copy a multi lines [‘n’ denotes the number of lines you want to copy] and use ‘p’
on before line to paste the line.
EDITING FILES USING EDITORS

2.6. In command mode use ‘dd’ for cut a single line or (n)dd for cut a multi lines
[‘n’ denotes the number of lines you want to cut] and use ‘p’ on before line to
paste the line.
EDITING FILES USING EDITORS
2.7. Use ‘u’ for undo the changes
EDITING FILES USING EDITORS

2.8. Use ctrl+r to redo the changes


EDITING FILES USING EDITORS

2.9 Use / and type any string the find the word in these file.
EDITING FILES USING EDITORS

2.10. Use ‘w’ for save, ‘q’ is for quit and ‘!’ for force
You can use these above values combine or you can use identically
EDITING FILES USING EDITORS
2.11. Using ‘cat’ command to verify the ouput.
Finding Files

Using locate to find files by name

The locate database is automatically updated every day. However, at any time the
root user can issue the updatedb command to force an immediate update.
[root@host ~]# updated
Finding Files

The locate command restricts results for unprivileged users. In order to see the resulting
file name, the user must have search permission on the directory in which the file resides.

Search for files with passwd in the name or path in directory trees readable by user on
host.

[user@host ~]$ locate passwd


/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
/etc/security/opasswd
/usr/bin/gpasswd
/usr/bin/grub2-mkpasswd-pbkdf2
/usr/bin/lppasswd
/usr/bin/passwd
Finding Files
Searching for files with find

The first argument to the find command is the directory to search. If the directory
argument is omitted, find starts the search in the current directory and looks for matches
in any subdirectory.

[root@host ~]# find / -name sshd_config


/etc/ssh/sshd_config

You might also like