0 ratings0% found this document useful (0 votes) 2K views10 pagesLab 4 - 2 - 6 Completed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
SEC 1GO
vifietfie Networking (ab 42.63
cisco Academy ——
ALS
4.2.6 Lab - Working with Text Files in the CLI
INDG This lab has been updated for use on NETLAB+.
a wrw.netdevaroup.com
Objectives
In this lab, you will become familiar with Linux command line text editors and configuration files.
Part 1: Graphical Text Editors
Part 2: Command Line Text Editors
Part 3: Working with Configuration
Instructions
Part 1: Graphical Text Editors
Before you can work with text files in Linux, you must be familiar with text editors.
Text editors are one of the oldest categories of applications created for computers. Linux, like many other
operating systems, has many different text editors, with various features and functions. Some text editors
include graphical interfaces, while others are only usable via the command line, Each text editor includes a
feature set designed to support a specific work scenario. Some text editors focus on the programmer and
include features such as syntax highlighting, bracket matching, find and replace, multi-line Regex support,
spell check, and other programming-focused features.
To save space and keep the virtual machine lean, the Cisco CyberOps Workstation VM only includes
ScITE as a graphical text editor application. SeiTE is a simple, small and fast text editor. It does not have
many advanced features, but it fully supports the work done in this course.
Note: The choice of text editor is a personal one. There is no such thing as a best text editor. The best text
editor is the one that you feel most comfortable with and works best for you,
Step 1: Open SciTE from the GUI
Va. Log onto the Workstation VM as the user analyst. using the password cyberops. The account analyst
is Used as the example user account throughout this lab.
~b. On the top bar, navigate to Applications > CyberOPS > ScITE to launch the ScITE text editor.
V6, SciTE is simple but includes a few important features: tabbed environment, syntax highlighting and more.
Spend a few minutes with SciTE. In the main work area, type or copy and paste the text below’
“Space, is big. Really big. You just wor't believe how vastly, hugely, mindbogglingly big itis. | mean, you
may think its a long way down the road to the chemist, but that's just peanuts to space.”
— Douglas Adams, The Hitchhiker's Guide to the Galaxy
Yd, Click File > Save to save the file. Notice that SciTE attempts to save the file to the current user's home
directory, which is analyst, by default. Name the fle space.txt and cick Save
Y ¢. Close SeITE by clicking the X icon on the upper right side ofthe window and then reopen SeITE.
/ §.. Click File > Open and search for the newly saved file, space.tet.
Could you immediately find space.txt?
NO
© 2018 -2020 Cisco andior its flats. lights reserved. Cisco Public Page 10f10 wivw.netacad.com4.2.6 Lab - Working with Text Files in the CLI
Vo. Even though SciTE'is looking atthe correct directory (fome/analys), space.tt is nt displayed. This is
because SciTE is looking for known extensions and .txt is not one of them. To display all files, click the
Gropdown menu atthe bettom ofthe Open File window and select All Files ().
Yh. Select space. to open i
Note: Wile the Linux fle systems do not rely on extensions, some applications such as Sc/TE may
J. attempt to use them to identify file types.
i. Close space.txt when finished.
Step 2: Open SciTE from the Terminal.
v/a. Alternatively, you can also open SciTE from the command line. Click the terminal icon located in the
Dock at the bottom of the desktop. The terminal emulator opens.
‘Type Is to see the contents of the current directory. Notice space.txt is listed. This means you do not
have to provide path information to open the file.
Type scite space.txt to open SeITE. Note that this will not only launch SciTE in the GUI, but it will also
automatically load the space.txt text file that was previously created.
[analyst@secOps ~1$ scite space.txt
V4. Notice that while SciTE is open on the foreground, the terminal window used to launch itis stil pen in
the background: In aditon, notice that the terminal window used to launch SciTE no longer displays the
prompt.
‘Why is the prompt not ae jin the terminal?
eonuse the Ter Ay 18 TUNDING Sci TE, ANd
Close this instance of = by either clicking the X icon as before, or by switching the focus back to the
terminal window that launched SeITE and stopping the process. You can stop the process by pressing
CTRL#C,
Note: Starting SciTE from the command line is helpful when you want to run SciTE as root. Simply
precede seite with the sudo command, sudo scite.
Vi. Close SeITE and move onto the next secon.
Part 2: Command Line Text Editors
While graphical text editors are convenient and easy to use, command line-based text editors are very
portant in Linux computers. The main benefit of command line-based text editors is that they allow for text
file editing from a remote shell on a remote computer.
Consider the following scenario. A user must perform administrative tasks on a Linux computer but is not
sitting in front of that computer. Using SSH, the user starts a remote shell to the aforementioned computer.
Under the text-based remote shell, the graphical interface may not be available which makes it impossible to
rely on graphical text editors. In this type of situation, text-based text editors are crucial.
Note: This is mainly true when connecting to remote, headless servers that lack a GUI interface.
The Workstation VM includes a few command line-based text editors. This course focuses on nano.
Note: Another extremely popular text editor is called vi. While the leaming curve for viis considered steep, vi
is a very powerful command line-based text editor. Its included by default in almost all Linux distributions and
its original code was first created in 1976. An updated version of viis named vim which stands for vi-
improved. Today most vi users are actually using the updated version, vim.
© 2018 -2020 Cisco andlor its alates. All ighs reserved. Cisco Public Page 2010 ‘wwn.netacad.com4.2.6 Lab - Working with Text Files in the CLI
Due to the lack of graphical support, nano (or GNU nano) can be controlled solely through the keyboard.
CTRL+0 saves the current file; CTRL+W opens the search menu. GNU mano uses a two-line shortcut bar at
the bottom of the screen, where a number of commands for the current context are listed. After nano is open,
press CTRL+G for the help screen and a complete list.
Va. Inthe terminal window, type nano space. txt to open the text file created in Part 1.
[analyst@secops ~]$ nano space.txt
Yb. nano will launch and automatically load the space. txt text fle. While the text may seem to be truncated
orincomplet, itis not. Because the text was created with no return characters and line wrapping is not
enabled, by default, nano s displaying one long line of text.
Use the Home and End keyboard keys to quickly navigate to the beginning and to the end of a line,
respectively,
What character does nano use t represent that a line continues beyond the boundaries ofthe screen?
Tearer Yon Sigh (7) or xe soir aan (a),
Ye NON Version.
As shown on the bottom shortcut lines, CTRL#X can be used to exit nano. nano will ask if you want to
ssave the file before exiting (‘Y’ for Yes, or N for ‘No’). If'Y’ is chosen, you will be prompted to press enter
to accept the given file name, or change the file name, or provide a file name if itis a new unnamed
document,
Y 4. To contro nano, you can use CTRL, ALT, ESCAPE or the META keys, The META key is the key on the
keyboard with a Windows or Mac logo, depending on your keyboard configuration.
Navigation in nano is very user friendly. Use the arrows to move around the files. Page Up and Page
Down can also be used to skip forward or backwards entire pages. Spend some time with nano and its,
help screen. To enter the help screen, press CTRL+G. Press q to quit the help screen and return to
document editing in nano. Press CTRL*X to exit out of nano.
Part 3: Working with Configuration Files
In Linux, everything is treated as a file, including the memory, the disks, the monitor output, the files, and the
directories. From the operating system standpoint, everything is a file. It should be no surprise that the system
itself is configured through files. Known as configuration files, they are usually text files and are used by
various applications and services to store adjustments and settings for that specific application or service.
Practically everything in Linux relies on configuration files to work. Some services have not one but several
configuration files.
Users with proper permission levels use text editors to change the contents of such configuration files. After
the changes are made, the file is saved and can be used by the related service or application. Users are able
to specify exactly how they want any given application or service to behave. When launched, services and
applications check the contents of specific configuration files and adjust their behavior accordingly.
Step 1: Locating Configuration Files
The program author defines the location of configuration for a given program (service or application). Because
ofthat, the documentation should be consulted when assessing the location of the configuration file.
Conventionally however, in Linux, configuration files that are used to configure user applications are often
placed in the user's home directory while configuration files used to control system-wide services are placed
in the /etc directory. Users always have permission to write to their own home directories and are able to
configure the behavior of applications they use.
Ja. Use the Is command to list all the files in the analyst home directory:
[analyst@secops ~]$ 1s -2
total 20
drwxe-x2-x 2 analyst analyst 4096 Mar 22 2018 Desktop
(© 2018 - 2020 Cisco andlor is afitates. Alright reserved. Cisco Publc Page 30110 ‘wiaw netacad.com2.6 Lab - Working with Text Files
cu
dewxe-xe-x 3 analyst analyst 4096 Apr 2 24:44 Downloads
drwxr-xr-x 9 analyst analyst 4096 Jul 19 2018 lab. support. files
drwxr-xr-x 2 analyst analyst 4096 Mar 21 2018 second_drive
1 analyst analyst 255 Apr 17 16:42 space. txt
While a few files are displayed, none of them seem to be configuration files. This is because itis
convention to hide home-directory-hosted configuration files by preceding their names with a." (dot)
character.
Use the 1s command again but this time add the -a option to also include hidden files in the output
[analyst@secops ~)$ 1s -la
total 144
ews 14 analyst analyst 4096 Apr 17 16:34 .
drwxr-xr-x 3 root root «4096 Mar 20 2018 ..
1 analyst analyst 424 Apr 17 12:52 .bash_history
i analyst analyst 21 Feb 7 2018 -bash_logout
analyst analyst $7 Feb 7 2018 .bash_profile
analyst analyst 97 Mar 20 2018 .bashrc
analyst analyst 141 Feb 7 2038 .bashre_stock
analyst analyst 4096 Mar 25 12:18 .cache
analyst analyst 4096 Jul 19 contig
analyst analyst 4096 Mar 22 2018 Desktop
analyst analyst 23 Mar 23. 2018 .dnre
analyst analyst 4096 Apr 2 14:44 Downloads
1
1
drwxr-xr-x 8.
0
2
1
a
3 analyst analyst 4096 Mar 22 2018 .gnupg
1
2
9
1
3
5
2
1
druxr-xe-x 1
ewan
analyst analyst 2520 Mar 24 12:32 .TCHauthority
analyst analyst 4096 Mar 24 2018 .idlerc
analyst analyst 4096 Jul 19 2018 lab.support. files
analyst analyst 61 Mar 24 12:36 .lesshst
analyst analyst 4096 Mar 22 2018 .1ocal
analyst analyst 4096 Mar 24 2018 .mozilla
analyst analyst 4096 Mar 21 2018 second_drive
analyst analyst 255 Apr 17 16:42 space.txt
Use cat command to display the contents of the .bashre file. This file is used to configure user-specific
terminal behavior and customization.
drwxrnsenx
dewxrxenx
drwsr-senx
drwx~
drwwr-xe-x
[analyst@secops ~]$ cat -bashre
export EDITOR=vim
PS1="\{\e(1/32m\) [\u@\h \WI\S\[\e(Om\] +
alias 1s="1s --color"
alias vie"vim"
Do not worry too much about the syntax of .bashre at this point. The important thing to notice is that
‘bashre contains configuration for the terminal. For example, the line PS1=\le[1;32m\u@Vh
\Wj\s\flefOml' defines the prompt structure of the prompt displayed by the terminal:
[usemame@hostname current_dir followed by a dollar sign, all in green. A few other configurations
include shortcuts to commands such as /s and vi. In this case, every time the user types /s, the shell
‘automatically converts that to 1s ~color to display a color-coded output for /s (directories in blue, regular
files in grey, executable files in green, etc.)
(© 2018 - 2020 Cisco andlor its alates. All ights reserved. Cisco Public Page 40110 wow netacad.com4.2.6 Lab - Working with Text Files in the CLI
4
The specific syntax is out of the scope of this course. What is important is understanding that user
configurations are conventionally stored as hidden fies in the user's home directory.
While configuration files related to user applications are conventionally placed under the user's home
directory, configuration files relating to system-wide services are place in the /etc directory, by convention.
Web services, print services, fip services, and email services are examples of services that affect the
entire system and of which configuration files are stored under etc. Notice that regular users do not have
‘writing access to /efc. This is important as it restricts the ability to change the system-wide service
configuration to the root user only.
Use the 1s command to list the contents of the /etc directory
[analyst@secops ~]$ 18 /ete
adjtime host cont mke2£s.cont ze_maps.cfg
apache-ant hostname mkinitepio.conf __request-key.cont
apparmor.d hosts mkinitepio.d request-key.d
axch-release ifplugd modprobe. resoly.cont
avahi initepic modules~load-d zesolvconf.cont
bash.bash_logout inputre rotd rpe
bash.bashre Aproute2 mtab rsyslog.cont
bingmt.d iptables nanore securetty
ca-certificates issue netconfig security
crypttab Java-T-openjdk nett services
dbus-1 Java-B-openjdk net sniff-ne shadow
default kernel nginx shadow-
depmod.d krbS.cont nscd.cont shells
dheped.cont 1d.so.cache nsswitch.conf skel
dheped.duia 1d.so.cont atp. cont ssh
dkms 1d.so.cont.d openldap sel
arire ibn openvewitch sudoers
elasticsearch —Libpaper.d os-release sudoers.d
environment Lightda pacman.conf sudoers .pacnew
ethertypes locale.cont pacman.conf-pacnew sysctl.d
filebeat locale.gen pacman.d systemd
fonts locale.gen.pacnex pam.d tmpfiles.d
fstab Localtime pango trusted-key. key
gai.cont login.defs Papersize udev
genre logrotate.conf passwd. vPower
group logrotate.d passud- vdpau_erapper.cfg
group- Logstash pemeia vinre
group.pacnes vm pkesil webapps
grub.d machine-id polkit-1 wgetre
gshadow mail.re profile xan
gshadon- makepkg.conf profile.d xeg
gshadow.pacnew —man_db.conf protocols xinetd.d
gtk-2.0 adadn.cont pulse yaourtre
gtk-3.0 mime. types e_keymaps
[analyst@secops ~]$ cat /etc/bash.bashre
'
# /etc/bash.bashre
(© 2018- 2020 Cisco andlor is affilates. Al rights reserved. Cisco Public
Page Sof 10
Use the cat command to display the contents of the bash.bashre file:
woww.neteesd.comWorking with Text Files in the CLI
‘Step 2: Editing and Saving Configuration fil
# Tf not running interactively, don't do anything
UL $+ I= 4G" 7] 46 return
[[ SDISPLAY ]] && shopt ~s checkwinsize
Psi="[\u@\h \W}\3 *
case $(TERM} in
xtern*|rxvt* |Eterm|aterm| kterm| gnome*)
PROMPT_COMMAND=$ {PROMPT_COMMAND:+$PROMPT_COMMAND; ) "prin
"5 {USER}" *${HOSTNAMESS. *)"""S (PND/#$HOME/\~T"*
s\007"
screen)
PROMPT_COMMAND™$ {PRONPT_COMMAND: +$PROMPT_COMMAND; } "printf "\033_%s@%5:%5\033\\"
ng {USER}" *§{HOSTNAMESE.*)"""5 (PND/#SHOME/\~)""
{ -© /ust/share/bash-conpletion/bash_completion } && . /usr/share/bash~
conpletion/bash_completi
[analystésecops ~18
The syntax of bash.bashrc Is out of scope of this course. This file defines the default behavior of the shell
for all users. If a user wants to customize his/her own shell behavior, the default behavior can be
overridden by editing the .bashre fle located in the user's home directory. Because this is a system-wide
configuration, the configuration file is placed under /etc, making it editable only by the root user.
Therefore, the user will have to log in as root to modify bash.bashre.
Why are user application configuration files saved in the user's home directory and not under /ate with all
the other system-wide configuration files?
ay do nove. SSi itt to
Linux is O Momi~OSer operas SUSIEM, PLACING User ApPPLICation iqueadk
1
Eves under /etc usowa Veep users Som being alle to Customize
Yneir applications
‘As mentioned before, configuration files can be edited with text editors.
Let’s edit .bashre to change the color of the shell prompt from green to red for the analyst user.
Va. First, open SeiTE by selecting Applications > CyberOPS > SciTE from the tool bar located in the upper
portion of the Workstation VM screen
Yb. Select File > Open to launch SciTE's Open File window.
Yc. Because .bashrois a hidden fle with no extension, SciTE does not display itin the file ist. I the Location
feature is not visible in the dialog box, Change the type of fle shown by selecting Alll Files (*) from the
type drop box, as shown below. All the files in the analyst's home directory are shown.
d, Select .bashre and click Open.
(© 2018 - 2020 Cisco andior its alate. Alrights reserved. Cisco Public Page 6 of 10 www.netacad.com4.2.6 Lab - Working with Text Files in the CLI
ve. Locate 32 and replace it with 31, 32 isthe color code for green, while 31 represents red.
© Gane ate ne
saa
Spon EOTORS
it. Save the file by selecting File > Save and close ScITE by clicking the X icon.
(9. Click the Terminal application icon located on the Dock, at the bottorn center of the Workstation VM
screen. The prompt should appear in red instead of green.
Bide tial window wich was en open lg hanger for ran ta? Ex
0. The -bashtt Sile is execyed and apotied when O terminal ts
/, Aish ofene! Sou senile alee nes 8 Ogg
‘The same change could have been made from the command line with a text editor such as nano. From a
new terminal window, type nano. bashrc to launch nano and automatically load the -bashre file in it:
[analyst@secops ~]$ nano .bashre
Guu nano 4.9.2 File: -bashre
export EDITOR)
Psi
alias 1
\[\er1732m\] C\ue\h \WI\S\ \efom\)
1s —-color™
allas vie"vin"
[ Read 5 Lines 1
°G Get Help 0 Write Out “WWhere Is °K Cut Text *J Justify °c cur Fos
J *x Exit *R Read File *\ Replace “U Uncut Text*T To Spell *_ Go To Line
|. Change 31 to 33. 33 is the color code to yellow.
V/ i, Press CTRLAX to save and then press ¥ to confirm, The text editor nano will also offer you the chance to
change the filename. Simply press ENTER to use the same name, -bashre.
The text ecitor nano wil end, and you wil be back on the shell prompt. This te reload the bash terminal
by entering the command bash in the terminal. The prompt should now appear in yellow instead of red.
(© 2018 - 2020 Cisco andlor ts afliates.Allrights reserved. Cisco Publlc Page 7 of 10 vwmnv.netacad.com4.2.6 Lab - Working with Text Files in the CLI
Step 3: Editing Configuration Files for Services
System-wide configuration files are not very different from the user-application files. nginx isa lightweight web
server that is installed in the CyberOPS Workstation VM. nginx can be customized by changing its
configuration file, which is located in /eto/nginx.
Y a. First, open nginx’s configuration file in a nano. The configuration file name used here is.
‘custom_server.conf. Notice below that the command is preceded by the sudo command. After typing
nano include a space and the -I switch. If prompted for a password, enter cyberops.
[analyst@secops ~]$ sude nano -1 /etc/nginx/custom_server.conf
[sudo] password for analyst
Use the arrow keys to navigate through the file.
GNU nano 4.9.2 /ete/ngins/eustom_server.cont
1
2 fuser html;
3 worker_processes 1;
4
5 ferror_log logs/error.log:
6 ferror_log legs/error.log notice;
7 ferror_log logs/error.log infor
a
9 wpia 1ogs/nginx pid:
10
re
12 events (
13 worker_connections 1024;
14)
15
16
17 http (
18 include mime. types;
19 default_type application/octet-strean;
20
21 #log_format main ‘Sremote_addr ~ Sremote_user [Stime_local] "$request” '
2 4 ‘setatus Sbody_bytes_sent "shttp_referer™ *
oe ‘"gnetp_user_agent" "shttp_x_forwarded_for"";
24
25 #access_log logs/access.log main
26
27 senafile ons
28 #tep_nopush ons
23
30 #keepalive_timeout 0;
31 keepalive_timeout 65;
32
33 #gzip ons
34
35 types_hash_max_size 4096;
(© 2018 - 2020 Cisco andlor its afiiates. Al rights reserved. Cisco Public Page 8010, wawnetacad.comFiles in the Ci
Lab - Working with
— oF
36 server_names_hash_bucket_size 1287
37
38 server {
33 Listen ai;
40 sezver_name localhost;
aa
42 foharset kois-r;
3
44 Haccess_log logs/host.access.1og main;
45
46 location / {
a root /usr/share/nginx/htm
48 index index.html index.htm;
49 ,
Note: Conventionally, .conf extensions are used to identify configuration files.
While the configuration fle has many parameters, we will configure only two: the port nginx listens on for
incoming connections, and the directory it will serve web pages from, including the index HTML
homepage file.
Notice that at the bottom of the window, above the nano commands, the line number is highlighted and
listed. On line 39, change the port number from 81 to 8080, This wil tell nginx to listen to HTTP requests
on port TCP 8080.
Next, move to line 47 and change the path from /usr/shareinginx/html/ to
Jusrishare/nginx/htmi/text_ed_lab/
Note: Be careful not to remove the semi-colon at the end of the line or nginx will throw an error on
startup.
Press CTRL#X to save the file. Press Y and then ENTER to confirm and use the eustom_server.conf as
the filename.
Type the command below to execute nginx using the modified configuration fle:
[analyst@secops ~19 sudo nginx -c custon_server.cont
Click the web browser icon on the Dock to launch Firefox.
On the address bar, type 127.0.0.1:8080 to connect to a web server hosted on the local machine on port
8080. A page related to this lab should appear.
After successfully opening the nginx homepage, look at the connection message in the terminal window.
What is the error message referring to?
The Error message WAS Bneraied by The Successful we Page
‘ssi ficon.ico File in She eSNG
To shut down the nginx webserver, press ENTER to get a command prompt and type the following i ae
command in the terminal window:
[analyst@secops ~]§ sudo pkill nginx
‘You can test whether the nginx server is indeed shut down by first clearing the recent history in the web
browser, then close and re-open the web browser, then go to the nginx homepage at 127.0.0.1:8080.
Does the web page appear?
No 7
© 2018-2020 Cisco andlor its afiiates, Al rights reserved. Cisco Public Page 9010 swavenetacad.com4.2.6 Lab - Working with Text Files in the CLI
Challenge Question: Can you edit the /etc/nginx/custom_configuration.contf file with SciTE? Describe the
process below.
Remember, because the file is stored under /etc, you will need root permissions to edit it
FLOM @ FEYMINAL WiNdoUS, jssue sudo SCIIE
Jetc/nairx! Custom configuration. ConF to launtin Scite a5 root,
Reflection
Depending on the service, more options may be available for configuration,
Configuration file location, syntax, and available parameters will vary from service to service. Always consult
the documentation for information.
Permissions are a very common cause of problems. Make sure you have the correct permissions before
trying to edit configuration files.
More often than not, services must be restarted before the changes take effect.
© 2018 - 2020 Cisco andior its alates. Al rights reserved. Cisco Public Page 100110 vw notacad.com
You might also like
LS, LL, W, Whoami, CD, PWD, Mkdir, MV, Rmdir, CP: Lab Session (6) : Networking
LS, LL, W, Whoami, CD, PWD, Mkdir, MV, Rmdir, CP: Lab Session (6) : Networking
7 pages