151
How to install ?
SUBLIME TEXT
152
CLI TEXT EDITOR
153
VI EDITOR
VI EDITOR 154
Linux use the improved versions of vi called vim
It has powerful features and becomes the standard on almost
every Linux distribution
It has the advantage of portability.
You can use the vi from any shell, terminal-based or character-
based connection over a network and no graphical interface is
required
The vi editor is called a bimodal editor because it functions in one
of two modes: command mode and insert mode
VI EDITOR - is invoked by 155- vi interprets any characters we type as
typing a colon
[:], while vi is commands and thus does not display
in Command them in the window.
Mode. - allows us to move through a file, and to
delete, copy, or paste a piece of text.
- The cursor will
jump to the - enables you to insert text into
last line of the the file. Everything that’s typed
screen and vi in this mode is interpreted as
will wait for a input and finally, it is put in the
command. file. The vi always starts in
command mode. To enter text,
- This mode you must be in insert mode. To
enables you to come in insert mode you simply
perform tasks type i.
such as saving
files, executing
commands.
WAYS TO START VI EDITOR 156
COMMANDS AND THEIR DESCRIPTION
vi filename: Creates a new file if it already not exist, otherwise
opens existing file.
vi -R filename : Opens an existing file in read only mode.
view filename : Opens an existing file in read only mode.
KEYS USED TO CHANGE TO & 157
FROM INSERT MODE
Key Description
i Changes to insert mode and places the cursor before the current
a character for entering text
o Changes to insert mode and places the cursor after the current
I character for entering text
A Changes to insert mode and opens a new line underneath the current
O line for entering text
Esc Changes to insert mode and places the cursor at the beginning of the
current line for entering text
Changes to insert mode and places the cursor at the end of the current
line for entering text
Changes to insert mode and opens a new line above the current line
for entering text
Changes back to command mode while in insert mode
COMMONLY USED IN COMMAND MODE
158
Key Description
w, W, e, E Moves the cursor forward one word to the beginning or end of the
next word, respectively
b, B Moves the cursor backward one word
53G Moves the cursor to line 53
G Moves the cursor to the last line in the document
0, ^ Moves the cursor to the beginning of the line
$ Moves the cursor to the end of the line
x Deletes the character the cursor is on
3x
Deletes three characters starting from the character the cursor is on
dw
Deletes one word starting from the character the cursor is on
d3w, 3dw
Deletes three words starting from the character the cursor is on
dd
Deletes one whole line starting from the line the cursor is on
159
COMMONLY USED IN COMMAND MODE (CONT.)
Key Description
d3d, 3dd Deletes three whole lines starting from the line the cursor is on
d$
d^, d0 Deletes from cursor character to the end of the current line
yw
Deletes from cursor character to the beginning of the current line
y3w, 3yw
Copies one word (starting from the character the cursor is on) into a
yy temporary buffer in memory for later use
Copies three words (starting from the character the cursor is on) into a
temporary buffer in memory for later use
Copies the current line into a temporary buffer in memory for later
use
COMMONLY USED IN COMMAND MODE
(CONT.) 160
Key Description
y3y, 3yy Copies three lines (starting from the current line) into a
y$ temporary buffer in memory for later use
y^, y0 Copies the current line from the cursor to the end of the
line into a temporary buffer in memory for later use
p
w, W, e, E Copies the current line from the cursor to the beginning of
the line into a temporary buffer in memory for later use
Pastes the contents of the temporary memory buffer
underneath the current line or after the current word
Moves the cursor forward one word to the beginning or
end of the next word, respectively
COMMONLY USED IN COMMAND MODE
(CONT.) 161
Key Description
k Moves the cursor up one line
h Moves the cursor to the last one character position.
G Moves the cursor to the last line in the document
J
Joins the line underneath the current line to the current line
Ctrl+g
u Displays current line statistics
. Undoes the last function (undo)
/pattern Repeats the last function (repeat)
?pattern Searches for the first occurrence of pattern in the forward direction
n Searches for the first occurrence of pattern in the reverse direction
Repeats the previous search in the forward direction
COMMONLY USED IN COMMAND
MODE (CONT.) 162
Key Description
N Repeats the previous search in the reverse direction
Moves the cursor down one line
j Displays current line statistics
Ctrl+g Positions cursor at the end line
Move cursor to top of screen
$
H Move to bottom of screen
L Move to bottom of screen
M Positions cursor to beginning of current sentence
Positions cursor to beginning of next sentence
(
)
COMMONLY USED AT COMMAND 163
MODE : PROMPT
Key Description
:q
:q! Quits from the vi editor if no changes were made
Quits from the vi editor and does not save any
:wq changes
Saves any changes to the file and quits from the vi
:w filename editor
:!date Saves the current document to a file called file name
:r !date Executes the date command using a BASH shell
Reads the output of the date command into the
:r filename document under the current line
Reads the contents of the text file called file name into
the document under the current line
164
VIM EDITOR (IMPROVISED
VERSION OF VI EDITOR)
Almost all Linux distributions, even older versions, come with the Vim 165
editor installed.
Vim stands for Vi Improved,
Meaning that Vim is a modified and improved version of the old Vi
text editor.
VIM EDITOR Pros: Vim supports automatic commands, digraph inputs (useful
in programming), split and session screens, tabs, coloured
schemes (color-coded by function), and tagging. It can be
configured with plugins and comes with a tutorial (invoked with
the vimtutor command). When you master the commands, Vim is
very efficient.
Cons: It does not have a GUI. The only way you can initiate Vim
is from the command line. The interface is user-unfriendly, while
some commands are not intuitive. Coding a file from scratch
would be too complicated. The learning curve can be steep, but
Vim is very popular in the Linux community.
166
STARTING VIM
VIM EDITOR If the filelist is missing, the editor will start with an empty
buffer. Otherwise, one out of the following four options
may be used to choose one or more files to be edited.
More details of vim command can be referred here :
https://www.computerhope.com/unix/vim.htm#:~:text=On%20Unix%2Dlike%20operating%
20systems,suited%20for%20editing%20computer%20programs
167
MAIN OPTIONS
VIM EDITOR Key Description
-t {tag} The file to edit and the initial cursor position depends on a "tag", a sort
of goto label. The {tag} is looked up in the tags file, the associated file
-q [errorfile] becomes the current file and the associated command is executed.
Mostly this is used for C programs, in which case {tag} could be a
function name. The effect is that the file containing that function
becomes the current file and the cursor is positioned on the start of the
function. For more information within vim, use the command ":help tag-
commands".
Start in quickFix mode. The file errorfile is read and the first error is
displayed. If errorfile is omitted, the file name is obtained from the
'errorfile' option (defaults to "errors.err" on most systems). Further
errors can be jumped to with the ":cn" command. For more information
within vim, use the command ":help quickfix".
168
MAIN OPTIONS
VIM EDITOR Key Description
file... A list of one or more file names. The first one will be the
current file and read into the buffer. The cursor will be
- positioned on the first line of the buffer. You can get to the
other files with the ":next" command. To edit a file that starts
with a dash, precede the filelist with a double dash ("--").
A single dash specifies that the file to edit is to be read from
standard input.
169
NANO
EDITOR
Nano is a revision of an older editor called Pico and comes 170
pre-loaded on most Linux installations.
Nano is an ideal lightweight editor for beginners.
It’s a lot easier to use than Vim, so it’s worth learning Nano for
quick configuration edits.
NANO EDITOR Nano text editor is pre-installed on macOS and most Linux
distros. To check the version:
Pros: It supports GNU Autoconf, interactive search-and-replace,
auto-indent, and spellcheck. Nano is intuitive and easy to use. It
lists the keystroke commands at the bottom of the editor, so you
don’t have to memorize or look them up.
Cons: The list of commands is short and some may be unintuitive.
To open an existing file or to 171
create a new file, type nano
followed by the file name:
NANO EDITOR Unlike vi, nano is a modeless editor, which means that
you can start typing and editing the text immediately
after opening the file.
More details of nano editor can be referred here :
https://linuxize.com/post/how-to-use-nano-text-
editor/#:~:text=GNU%20nano%20is%20an%20easy,%2D8%20encoding%2C%20and%20more
172
TOPIC 4: MANAGE USERS,
GROUPS AND
PERMISSIONS
LEARNING OUTCOMES 173
Explain user and group accounts in Linux system environment
Explain the configuration files to manage user and group
accounts
Use graphical utilities to manage users and groups
Use command-line utilities to manage users and groups
Use command to assign and modify password to the users
REQUIREMENTS
graphical tool: User accounts
command-line tools: sudo, adduser, usermod, visudo, useradd,
passwd
LEARNING OUTCOMES 174
Explain administrator privileges tasks in Linux system environment
Define the root user
Use graphical utilities to assign root privileges to regular users
Use command line utilities to modify the /etc/sudoers
configuration file
Use command line to switch users
REQUIREMENTS
config. files: /etc/passwd, /etc/group, /etc/shadow, /etc/skel/,
/etc/sudoers
LEARNING OUTCOMES 175
Demonstrate file and directory permissions in Linux system
environment
Explain file and directory ownership and permissions
Perform command chown and chgrp to modify the permissions
Perform chmod to modify the permissions
Identify the default permissions created on files and directories
Perform special file and directories permissions
REQUIREMENTS
command-line tools: ls -l, chown, chgrp, chmod, umask
176
USER AND GROUP
ACCOUNTS IN LINUX
SYSTEM ENVIRONMENT
This Photo by Unknown Author is licensed under CC BY-ND
177
CREATE &
MODIFY USERS
CONFIGURATION FILES
CONFIGURATION FILES 178
CONFIGURATION FILES EXAMPLE :
179
CONFIGURATION FILES
/etc/passwd
/etc/passwd
User account information
1 23 4 5 67
180
CONFIGURATION FILES
/etc/passwd
1 Username: It is used when user logs in. 5 User ID Info: The comment field.
2 Password: An x character indicates Home directory: The absolute path to the
that encrypted password is stored 6 directory the user will be in when they log
in /etc/shadow file.
in.
3 User ID (UID): Each user must be 7 Command/shell: The absolute path of a
assigned a user ID (UID).
command or shell (/bin/bash).
4 Group ID (GID): The primary group
ID (stored in /etc/group file)
181
CONFIGURATION FILES
/etc/group
/etc/group Group account information
1 23 4
182
CONFIGURATION FILES
/etc/group
1 Group name: Name of group.
2 Password: Generally password is
not used. It can store encrypted
password.
3 GID: The group ID
4 Group list: The list of user names who are
members of the group.
183
CONFIGURATION FILES
/etc/shadow
/etc/shadow Secure account information & only can be
viewed by administrative privileges.
12
3456 7 8 9
184
CONFIGURATION FILES
/etc/shadow
1 Username: It is used when user logs in. 5 Maximum: Num. of days after password
must be changed (99999 indicates user can
2 Password: The encrypted
keep the password many years).
password. If it is starts with a
exclamation mark (!) means that 6 Warn: Num. of days to warn user of an
the password is blocked. expiring password (7 for a full week).
3 Last password change: Number of
days (since Jan. 1, 1970) that the 7 Inactive: Num. of days after the password
password was last changed. expires that accounts is disabled.
4 Minimum: Num. of days before 8 Expire: Num. of days (since Jan. 1, 1970) that
password may be changed (0 account has been disabled.
indicates it may be changed at any
time). 9 Reserved.
185
USER’S HOME DIRECTORY
When the home directory for a
new user is created, it is
initialized with files from the
/etc/skel directory.
Ubuntu creates
a /home/username directory for that user
with her/his username.
This directory is often referred as "the
user’s home directory"
186
THE HOME DIRECTORY IS:
HOME DIRECTORY The directory the user will be in when they log in (on terminal).
Where your Desktop resides.
Where your documents, pictures, music, videos, audio, and pretty much
everything else can be stored.
Where your application settings are stored, in hidden files and directories (their
names start with a dot “.” )
The only place (with the exclusion of removable drives and the /tmp directory)
within the Ubuntu file system where a user can freely create/modify/remove
files and directories without needing root permissions or the sudo command.
HOME DIRECTORY WHAT USERS CAN DO ON THEIR HOME187
DIRECTORY?
Each user has full read/write/execute access to his or her
home directory.
Each user can make their home directory unreadable by
other users.
Each user can fully customize their Desktop
layout/background, sounds, window manager,
applications, etc.
188
CREATE &
MODIFY USERS
GRAPHICAL TOOLS
189
INSTALL GUEST ADDITION
Click run to run the software
VirtualBox Guest Additions are a collection of device drivers and system applications designed to achieve
closer integration between the host and guest operating systems. They help to enhance the overall
interactive performance and usability of guest systems. Easy mouse pointer integration
190
MUST
AUTHENTICATE
THE PASSWORD
EVERYTIME
CHANGE HAS
BEEN MADE
191
RUN USERS TOOL
You can manage users using 1. Click here
the Users Accounts tool.
2. Click
To find this tool, click Arrow Settings
Down Indicator › Settings ›
User
3. Click Users
** The GUI settings might be different from version to version
192
UNLOCK THE USER SETTINGS
Click the Unlock button
and enter your password
to unlock the user
settings.
GUI for Ubuntu 20.04
** The GUI settings might be different from version to
version
193
CREATE A NEW USER ACCOUNT
Click the Add user.. button at the
current user accounts.
Complete the following three fields:
The Account Type field contains a list of
user account types.
The Full Name field contains a friendly
display name.
The Username field is for the actual
username (fill with a lowercase).
Once all fields are filled in, click Add.
CREATE A NEW USER ACCOUNT/ 194
CHANGE PASSWORD
Password you can set the
password for the new user you
add.
The Remove User button can be
used to remove the user not being
use anymore.
195
CREATE &
MODIFY USERS
COMMAND-LINE TOOLS
196
ADDUSER adduser
On terminal, type
sudo adduser luth
And press Enter.
197
adduser
ADDUSER Provide the password. Then, press Enter.
Re-type the same password for the
confirmation. Then, press Enter.
198
ADDUSER adduser
Provide other
information/comments
(if done, press Enter)
199
adduser
ADDUSER Finally, press Y and then Enter to finish.
200
useradd
USERADD If you want to use the useradd command, you have to set up
everything manually.
On terminal, type
sudo useradd -m -k /etc/skel/ -s /bin/bash -c “Nelia M. Q” nelia
and press Enter.