Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Linux Basics

A) GIT: Version Control System, really useful for tracking your changes.
TODO: try.github.com 15 mins tutorial.
B) Vi : Powerful Editor: Recommended to be used.
Useful commands to remember
:q - quit
:wq - Save and close
:syntax on - Turn on Syntax highlighting for C programming and other languages
:set number - Turn on the line numbers
TODO: 25-30 mins vimtutor
C) We learned different commands
a) whatis - provides a one line description of the commands
b) su : change users or become superuser: Remember the difference between su - <username> and
su <username>
c) touch - create zero byte files, mainly used for changing the timestamps of the file.
d) gcc -Wall -pedantic -g <C source file> -o <Executable file>
-Wall -pedantic : to check for all the warnings and errors if any.
-g to create the symbol file to be used by gdb
-o to create the executable file.
e) GDB: GNU debugger
gdb -tui <Program name>
-tui for listing the source while debugging
b <linenumber> to set the break point
p <variable name> to print the value of the variable
bt to print the stack call, mainly useful to find segmentation fault when multiple functions are
called.
f) make: If your program source file name is test.c, then you can directly write make test, this would
compile the test.c program. Remember this it's a faster way.
h) /etc/issue : Contains the message which is displayed on terminal before login.
i) /etc/motd: Contains the message which is displayed on terminal after login.
j) cal and date: Display calendar and date.
Remember the escapes sequences used in the /etc/issue. man agetty lists them.
TODO:
a) Do some work on all these commands,
b) read there man pages.
c) create one small program using vi with syntax on, compile it using gcc, try to debug it using gdb.,
try to track that program using git, upload them to a remote server, then pull your code, check if its
the same.
d) Try to change the messages before login, after login.
Vijay Kumar, RC Bose Center of Cryptology and Security, Indian Statistical Institute, Kolkata, India

A) We learned how to update the debian system using apt-get.


apt-get update - Sync with Repository
apt-get upgrade - Upgrade installed packages
apt-get dist-upgrade - Upgrade distribution packages.
apt-get install <Package Name> - Install the package
apt-get remove <package name> - Uninstall the package.
TODO:
Read about apt-get., do man apt-get, install a package call cmatrix, uninstall it and install it again.
Tip: As mostly, updating takes time, you can club all the commands like
apt-get update && apt-get upgrade && apt-get dist-upgrade && poweroff
poweroff would shutdown the system after everything is updated.
B) Using brackets to do work faster, as I gave the example of creating directories.
touch {2012,2013,2014}_{Jan,Feb,Mar} would create 9 files with 2012_Jan, 2012_Feb, 2012_Mar
and same with 2013,2014.
C) Copy preserve file permissions and timestamps
cp -av/pv
-a similar to preserve,
-p preserve
-v verbose.
TODO: read man cp and copy something and check if the file permissions and timestamps are
preserved.
D) chown, chgrp, chmod
TODO: do some practice with this
E) hostname - prints out the hostname of the machine which is stored in /etc/hostname.
F)Pipes:
> direct normal output
2> direct error output
&> direct all output
G) Translate
tr 'a-z' 'A-Z' converts from smaller to uppercase.
H) Combine two commands (cal 2007 ; cal 2008)

Vijay Kumar, RC Bose Center of Cryptology and Security, Indian Statistical Institute, Kolkata, India

I) tee command - saves output in file as well as forward it.


J) cat /proc/cpuinfo - provides information about cpu
/proc/meminfo - provides information about memory/ RAM
/proc/version - provides information about the version of your system.
K) less/ more - prints information one per page.
head/tail - first 10 lines / last 10 lines.
L) cut / wc / sort / diff
cut uses a delimiter and to print the fields
TODO:
Scenario: Supposed you got access via shell to a linux system and extract some information from it.
Create a script (Present me everything in one script).
a) Create a alice, bob, eve with the password "password"
HINT: set password using chpasswd, look some examples in google to change from cmdline.
b) Login from eve.
c) Copy and preserve all the configuration files from /etc and save it in eve home directory in the
folder etc-backup-YYYYMMDD, direct all errors to cp.err
d) Change the owner of all the files in the folder just created to bob and the group of all the files to
alice and change the permission of all the files to 440 i.e r--r----HINT: would have to be logined as root
e) Provide me all the unique shells used by the user present in the system in CAPS.
HINT: /etc/passwd file contains all the shells, three four commands would be used.
f) Cover your tracks, clear out the /var/log/auth.log (Have a look at this file and create a backup
before clearing), clean your terminal history
HINT: man pages would help you.
h) Delete all the user bob, alice, eve. Make sure you delete there files too.
A) sed: Short from stream editor really very useful.
in vi editor
:s/test/learn would replace test to learn in current line but only first instance.
:s/test/learn/g would replace test to learn in current line all the instance.
:s/test/learn/gi would replace test (all cases) to learn in current line all the instance.
:%s/test/learn/gi would replace test to learn in the file (all lines)
B) Bash configuration files
-

~/.bash_profile
~/.bash_history - contains all the history of the commands.
~/.bash_logout - contains the command which are executed when bash is exited
~/.bashrc
- setting of variables for bash.
/etc/profile
- setting of PATH variable and PS1

C) last, lastb, lastlog Vijay Kumar, RC Bose Center of Cryptology and Security, Indian Statistical Institute, Kolkata, India

last - shows all the login attempts and the reboot occurred.
lastb - shows all the bad login attempts
lastlog - shows the list of all the users and when did they login.
D)tar - tar archiving utility
-c create archive
-t list the content of the file
-x extract the files
-j bzip2 format
-z gzip format
E) Linux has six runlevels 0-6
Scripts are contained in /etc/rc[0-6,S].d/
Each folder contains the scripts which are followed by either K or S. If the first letter is K that script
is not executed. If S, that script is executed.
/etc/inittab contains the default run level.
F) pstree - Process tree
G) Sysctl - configure kernel parameters
/etc/sysctl.conf - contains the variables for kernel parameters.
sysctl -a display all the kernel parameters
sysctl -w <kernel parameter>
H) Kernel Modules
contained in /lib/modules/$(uname -r)/
lsmod - list all loaded modules
modprobe - load kernel modules
lspci - list all pci devices
lsusb - list all usb devices
hal-device - list all the Hardware Abstraction layer devices
I) mount and umount - Mount/unmount a filesystem
J) Groupadd, groupdel/ groupmod
-add, delete or modify any group
K) SUDO
/etc/sudoers
Vijay Kumar, RC Bose Center of Cryptology and Security, Indian Statistical Institute, Kolkata, India

-File should be edited by visudo command


Follows a pattern like
username ALL=(ALL)
For example:
--User Alias Specification
User_Alias LIMITEDTRUST=student1,student2
--Command Alias Specification
Cmd_Alias MINIMUM=/etc/rc.d/init.d/httpd
--User privilege specification section
LIMITEDTRUST ALL=MINIMUM
Users student1 and student2 can use sudo only with the commands listed with MINIMUM (httpd)
users student1, student2 should exists in the group sudo. (/etc/group)
man sudoers
L) nm-applet - Just a applet for network manager.
TODO:
Have a look at the man pages of all the commands at read the abstract, some common options
a) Turn off the ping responses for your system permanently and turn on the Syn-cookies protection
mechanism. {Search on Google}
b) Use your previous script to create three users alice, bob, eve.
-create a folder dept inside it two folder hr, web.
-create two group hr and web.
-change group of web folder to web and hr to hr.
-add alice and bob user to web group
-add alice to hr group.
-check that bob is not able to enter in the hr folder and alice is able to enter in both hr and web
folder
-add user bob to sudo group and check if it is able to run sudo ifconfig ?

Vijay Kumar, RC Bose Center of Cryptology and Security, Indian Statistical Institute, Kolkata, India

You might also like