Kali Linux Command Example
Rosetta, 2021
Example of Kali Linux Commands
Here you find the list of kali linux command including File management command, what is
vim and details about vim, user and group management command of kali linux like create,
delete and alter user AND group, create and extract backup, system management, network
management and server management command of kali linux 2019.1
In this article, i have explained all the kali linux terminal command in detail with the
example.
Basic Commands
[root@kali ~] pwd
[pwd will show the Present working directory]
[root@kali ~] ls
[ls will show the list of file and directory of present working directory.]
[root@kali ~] ls b*
[ls b* will show the list of file and directory starting with b and end with anything.]
[root@kali ~] ls -l
[Listing of all files and directory along with attributes(i.e. more detailed format like file
permission,file size etc.]
[root@kali ~] ls -a
[Listing of all files and directory along with hidden file or file starting with periods (i.e. file
stating with * like *bashrc]
[root@kali ~] ls -R
[show the listing of file and directory in tree structure.]
[root@kali ~] cat Kalirosetta.txt
[user can use the command cat to see the preview of Kalirosetta.txt file.]
[root@kali ~] cat > Linux.txt
[use to create file]
[root@kali ~] cat Kalirosetta.txt Linux.txt >>new.txt
[transfer the content of Kalirosetta.txt and Linux.txt to new.txt file.]
Rosetta Techonology | offensive security certified professional training 1
Kali Linux Command Example
Rosetta, 2021
[root@kali ~] cd
[To change the directory.]
[root@kali ~] cd com
[go to directory name com .]
[root@kali ~] cd ..
[change the directory one level back.]
[root@kali ~] cd ../..
[change the directory two level back.]
[root@kali ~] cd ~
[change the directory to home directory.]
[root@kali ~] Vi <filename>
[It will create a Blank file.]
[root@kali ~] Vi <file1> <file2> <file3>
[It will create multiple file at once.]
[root@kali ~] Vi file1.txt
[to open file1.txt using Vi]
[i- to insert text in file1.txt]
[press Shift+: and then type wq to save and quit.
: q to exit without any changes in file
: x to save changes and exit.]
[root@kali ~] mkdir com
[It will create a directory name com]
[root@kali ~] mkdir com lap mob
[To create multiple directories]
[root@kali ~] mkdir -p com/lap/mob
[To create a directory with their subdirectory]
[root@kali ~] cd -
Rosetta Techonology | offensive security certified professional training 2
Kali Linux Command Example
Rosetta, 2021
[go to last working directory.]
[eg:currently user in /home/Kalirosetta/Desktop directory and user last working directory is
/root/Desktop . so as and when user type cd - user directly go to /root/Desktop directory.]
[root@kali ~] rm Kalirosetta.txt
[rm remove the file Kalirosetta.txt.]
[root@kali ~] rmdir com
[rmdir remove the directory name called com only if the com directory is empty.]
[root@kali ~] rm -rf com
[rm -rf remove the directory and also the content or data available in directory.]
[root@kali ~] cp Linux.txt /root/Desktop
[copy the file Linux.txt to /root/Desktop Directory.]
[root@kali ~] cp -r com /root/Desktop
[copy the directory com to /root/Desktop directory.]
[root@kali ~] mv Kalirosetta.txt /home
[move the file Kalirosetta.txt to /home directory]
[root@kali ~] mv Linux.txt Linux2.txt
[rename the file Linux.txt to Linux2.txt]
How to change the file or directory permission?
chmod command is used to change the permission.
File or Directory permission can be change in two ways:
Method 1
chmod <permission> <file or directory name>
eg: 1 : if user file permission change from rwx to rw only
chmod u+rw filename
2 : if user and group file permission change from rwx to rw only
chmod ug+rw filename
Rosetta Techonology | offensive security certified professional training 3
Kali Linux Command Example
Rosetta, 2021
Method 2
chmod <permission> <file or directory name>
eg:1 : if user file permission change from rwx to rw only ,group file permission change from
rwx to r only and other file permission change from rwx to r only.
chmod 644 filename
File Permission
- rwx rwx rwx
- means file
r means read
w means write
x means excute
first rwx is for user permission
next rwx is for group permission
and last rwx is for other permission
- means permission is for filea
d means permission is for directory
l means for links
p means for process file
s means for socket file
b means for block device
c means for character device
Note:if permission started with d instead of - .It means particular permission is for directory.
How to change the file or directory ownership?
chown command is used to change the ownership of a file or directory.
File or Directory owner can be change this ways:
Changing file ownership
You can change the owner of a file by using the chown command
chown <new user name> <file name>
eg:1 : I wanted to change the owner of file from "Kalirosetta" to "linux".
chown linux filename
Changing group ownership
You can change the owner of group by using the chgrp command
chgrp <new user name> <file name>
Rosetta Techonology | offensive security certified professional training 4
Kali Linux Command Example
Rosetta, 2021
eg:1 : I wanted to change the owner of group from "Kalirosetta" to "linux".
chgrp linux filename
changing user and group ownership
chown <user>:<group> filename
eg: if user want to change both user and group ownership
chown kalirosetta:linux filename
VIM
Vim is simply an improved version of Vi. It pretty much has a ton of stuff that Vi doesn‟t.
Within Vim you can see the differences between Vi and Vim by running the following
command :h vi-differences.
[root@kali ~] Vi <filename>
[It will create a Blank file.]
[root@kali ~] Vi <file1> <file2> <file3>
[It will create multiple file at once.]
[root@kali ~] Vi file1.txt
[to open file1.txt using Vi]
[press i - to insert text in file1.txt]
[press Shift+: and then type wq to save and quit.
: q to exit without any changes in file
: x to save changes and exit.]
User & Group Administration
User
1 : Show the details of all users
user -D
2 : To add new user in system
useradd name
3 : To delete particuler user from the group
userdel -r name
4 : usermod command is used for modifying user
eg: If user want to insert comment then
usermod -c "comment" user name
Rosetta Techonology | offensive security certified professional training 5
Kali Linux Command Example
Rosetta, 2021
5: To set the password on particuler user command will be
passwd username
Group Administration
1 : To add new group named projectX command will be
groupadd projectX
2 : To remove group named projectX command wil be
groupdel projectX
3 : To add user in a group
usermod -G <Group name> <username>
eg: To add username kalirosetta in a group name called projectX
usermod -G project X kalirosetta
4 : To add user in a multiple group
usermod -G <Group name><Group name> <username>
eg: To add username kalirosetta in a group name called projectX and project Y
usermod -G projectX,projectY kalirosetta
5 : How to provide admin right to specified user in a particuler group
gpasswd -A username groupname
6 : To add user in a group
gpasswd -a username groupname
7 : To remove group named projectX command wil be
gpasswd -d username groupname
8 :create new group called abcd
newgrp abcd
Note: User can be add in a group via usermod as well as
gpasswd command
User and Group Databases file
1 : To check the all set password go to directory
cat /etc/passwd
2 : To see password which is set in encrypted form
cat /etc/shadow
3 : To check detail of all the group
cat /etc/group
Rosetta Techonology | offensive security certified professional training 6
Kali Linux Command Example
Rosetta, 2021
BACKUP
Commands for Backup
tar <options> <destination> <source>
Options:
c -- create
v -- verbose means it will show all the error while creating creating backup.
p -- same permission i.e. maintains the same permissions of file which is backed-up
f -- specifies filename
t -- table of content
x -- extract to
z -- zip/gzip
w -- ask for confirmation
To create a backup
Type1: tar --create --verbose --same-permission --file /usr/backup1 /home /etc
Type2: tar -cvpf /usr/backup1 /home /etc
c-create
v-verbose
p-maintains the same permissions of file which is created
f-to create a file
/usr is the directory were backup is saved
backup1 is the name of backup file created
/home & /etc are the directory for which backup is created
To extract the content from backup
tar -xvpf /usr/backup1
To extract a specific file from backup
tar -xvpf /usr/backup1 /home/kalirosetta.txt
To extract kalirosetta.txt file from backup1 to the directory /home/kalirosetta.txt
To list the content of backup
tar -tvf /usr/backup1 | more
list view of files in backup useful for recovering file which name is not known
To create a zip file
zip <filename> <destination>
e.g. zip linux /usr
linux is the filename
Rosetta Techonology | offensive security certified professional training 7
Kali Linux Command Example
Rosetta, 2021
/usr is the directory to save the zip file
To extract the zip file
unzip linux /etc
To create a gzip file
gzip filename
e.g: gzip linux
To extract a gzip file
gzip -d filename
e.g.: gzip -d linux.gz
SYSTEM COMMANDS
uname -a
Display linux system information
uname -r
Display kernel release information
last reboot
Show system reboot history
date
Show current date and time
cal
Show current month calendar4
whoami
Who you are logged in as
finger user
Display information about user
cat /proc/cpuinfo
Show cpu info
cat /proc/meminfo
Show memory information
man command
Show manual for command
Rosetta Techonology | offensive security certified professional training 8
Kali Linux Command Example
Rosetta, 2021
df
Check filesytem storage
du
Check subdirectories
df -h
Shows file size which is user readable
du --max-depth=1 -h
Check subdirectories by one level down
whereis app
Show possible location of app
which app
Show which app will be run by default
free
To check ram & swap partition usuage
free -g
To see usuage in gigabytes
dd if=/dev/zero of=/swapfile bs=1024 count=1024
dd to create a storage file
if=/dev/zero : Read from /dev/zero file. /dev/zero is a special file in that provides as many
null characters to build storage file called /swapfile.
of=/swapfile : Read from /dev/zero write storage file to /swapfile.
bs=1024 : Read and write 1024 BYTES bytes at a time.
count=1024 : Copy only 1024 BLOCKS input blocks.
mkswap /swapfile
To setup a linux swap area in a file.
swapon /swapfile
Enable the swap file.
swapoff /swapfile
Disable the swap file.
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the
number of blocks. For example, the block size of a 64 MB swap file is 65536.
lvextend -l +100 /logical/volume00
Extend the logical volume 00 from blank space i.e. 0mb to volume 00 with 100 mb...
ctrl+alt+f1
GUI (Graphical mode) to text mode i.e. CLI(Command Line Interface)
Rosetta Techonology | offensive security certified professional training 9
Kali Linux Command Example
Rosetta, 2021
ctrl+alt+f7
Text to graphic mode
Types Of Boot Loader
grub = grand unified boot loader
lilo = linux bootloader
kcontrol &
Configure the kde enviroment
gnome-control-center
Configure the gnome enviroment
switchdesk kde
Set the default startup to kde
switchdesk gnome
Set the default startup to gnome
up2date-config
Configure the red hat for update
mount /dev/sda1 /tmpdir mount the sda1 file in tmpdir directory
mount /dev/sda0 /tmpdir mount the sda0 file in tmpdir directory
unmount /tmpdir/boot unmount boot directory
unmount /tmpdir unmunt tmpdir directory
sync
Sync the changed or changes take effect
top
Will show the running process list
gnome-system-monitor
Show the graphical mode of running process
uptime
Show how long the system is running from last boot
load average of first no show the the total load in last one minute
load average of second no show the the total load in last five minute
load average of third no show the the total load in last fifteen minute
NETWORK MANGEMENT
ifconfig
Show the ip address eth0
Rosetta Techonology | offensive security certified professional training 10
Kali Linux Command Example
Rosetta, 2021
iwconfig
show the ip address of wireless connection
ip addr show
Display all network interfaces and ip address
(a iproute2 command,powerful than ifconfig).
ip address add 192.168.0.1 dev eth0
Set ip address
ethtool eth0
Linux tool to show ethernet status
mii-tool eth0
Linux tool to show ethernet status
ping host
Send echo request to test connection
whois domain
Get who is information for domain
dig domain
Get DNS information for domain
dig -x host
Reverse lookup host
host kali.org
Lookup DNS ip address for the name
hostname -i
Lookup local ip address
wget file
Download file
wget -c file
Continue stopped download
wget -r url
recursively download files from url
netstat -tupl
Listing all active listening ports
hostname
Show system host name
Rosetta Techonology | offensive security certified professional training 11
Kali Linux Command Example
Rosetta, 2021
SSH-Secure Shell
ssh user@host
Connect to host as user
e.g.: ssh admin@kalirosetta.com
ssh -p port user@host
Connect using port p
e.g. ssh -22 admin@kalirosetta.com
ssh -D port user@host
Connect and use bind port
FTP-File Transfer Protocol
ftp
Type ftp in terminal then
ftp> open ftp.kali.com
The above command will open ftp session and then type your ftp username & password.
username:ftp username
password:ftp pasword
APACHE SERVER CONFIGURATION
Apache is the most widely used Web Server application in the world with more than 50%
share in the commercial web server market. Virtual hosting is one such feature that allows a
single Apache Web Server to serve a number of different websites. The word, Apache, has
been taken from the name of the Native American tribe „Apache‟, famous for its skills in
warfare and strategy making.
Installing apache from the source require the –devel package to be installed on your server.
You can find the latest available version of Apache, you can download it here:
http://httpd.apache.org/download.cgi
Once you download the source file move it to the /usr/local/src folder.
[root@kali ~] cd /usr/local/src
>Go to /usr/local/src directory
[root@kali ~] gzip -d httpd-2.2.26.tar.gz
>Apache file is archived with .tar.gz so first use gzip command to extract the data from gzip.
[root@ kali ~] tar xvf httpd-2.2.26.tar
>Now use tar command to extract the data from .tar archived file.
Rosetta Techonology | offensive security certified professional training 12
Kali Linux Command Example
Rosetta, 2021
[root@ kali ~] httpd-2.2.26
[root@ kali ~] ./configure –help
>see all configuration option
[root@ kali ~] ./configure –prefix=/usr/local/apache –enable-so
>The compilation of Apache within the /usr/local/apache directory with the DSO capability.
The –enable-so option, can load required modules to apache at run time via the DSO
mechanism rather than requiring a recompilation.
[root@ kali ~] make
[root@ kalil ~] make install
>use to make the file and install
[root@ kali ~] iptables -I INPUT -p tcp --dport 80 -j ACCEPT
>command to open port 80 in firewell
Configure the virtual host for multiple domain hosting
There are two types of virtual hosts supported by Apache –
1.Name-based virtual host
2.Address-based or IP based virtual host
1.Name-based Virtual Host
Name based virtual hosting is used to host multiple websites on a single IP address.for this
user have to edit the httpd.conf file & copy the colored content below and paste it.
NameVirtualHost *:80
<VirtualHost 192.168.0.108:80>
ServerAdmin linux@kalirosetta.com
DocumentRoot /var/www/html/kalirosetta.com
ServerName www.kalirosetta.com
</VirtualHost>
<VirtualHost 192.168.0.108:80>
ServerAdmin tuts@kalirosetta1.com
DocumentRoot /var/www/html/kalirosetta1.com
ServerName www.kalirosetta1.com
</VirtualHost>
Now check the configuration file and make sure all “syntax Ok” with below command
[root@kali ~] httpd –t
Rosetta Techonology | offensive security certified professional training 13
Kali Linux Command Example
Rosetta, 2021
2.IP-based Virtual host
Listen 192.168.0.10:80
<VirtualHost 192.168.10.18:80>
ServerAdmin linux@kalirosetta.com
DocumentRoot /var/www/html/kalirosetta.com
ServerName www. kalirosetta.com
</VirtualHost>
<VirtualHost 192.168.10.19:80>
ServerAdmin tuts@ kalirosetta.com
DocumentRoot /var/www/html/kalirosetta1.com
ServerName www.kalirosetta1.com
</VirtualHost>
In ip based hosting, multiple ip address is used as shown above for configuration
If user want to deploy the php website then mod_php enabled on your server
This file is find in /etc/httpd/conf.d/ directory.
Check the mod_php with following command
httpd -M | grep "php5_module"
| means pipe and show the details in table views i.e.in more format
grep is like finding the particular word in whole directory here we are looking for
php5_module so command will be grep "php5_module"
SECURITY
Things to be considered before configuring apache server.
1.Hiding Apache version and OS information:
Apache displays its version and the name of the operating system in errors. A hacker can use
this information to launch an attack. so server administration must hide the server signature.
This can be with following command
vim /etc/httpd/conf/httpd.conf
>Go to the above directory
ServerSignature Off
>Off the default signature
service httpd restart
>restart the server to take effect the changes
Rosetta Techonology | offensive security certified professional training 14
Kali Linux Command Example
Rosetta, 2021
2. Disable Directory Listing
If /var/www/ don‟t have the index file then webserver shows the document root directory
This feature could be turn off for a specific directory through “options directive” available in
the Apache configuration file.
<Directory /var/www/html>
Options -Indexes
</Directory>
3.Restricting Access to files outside the root directory
Configure the file like given below:
<Directory/>
Options None
AllowOverride None
Order deny,allow
Deny from all
</Directory>
This will not allow user to access outside the web root directory
HOW TO INSERT RESTRICTION.
To view the current iptables configuration
iptables -L
How to block all connections from a specific IP Address.
iptables -A INPUT -s (ip address) -j DROP
e.g.: iptables -A INPUT -s 192.168.1.22 -j DROP
How to block all of the IP Addresses in the
192.168.1.1/24 network range.
Standard method: iptables -A INPUT -s 192.168.1.1/24 -j DROP
OR
Netmask method: iptables -A INPUT -s 192.168.1.1/255.255.255.0 -j DROP
How to block SSH connections from any IP address.
iptables -A INPUT -p tcp --dport ssh -j DROP
Rosetta Techonology | offensive security certified professional training 15
Kali Linux Command Example
Rosetta, 2021
How to block SSH connections from a specific IP Address.
iptables -A INPUT -p tcp --dport ssh -s 10.10.10.10 -j DROP
For tcp protocol use -p tcp
& for udp protocol use -p udp
The changes that you make to your iptables rules will be scrapped the next time that the
iptables service gets restarted unless you execute a command to save the changes
For Ubuntu:
sudo /sbin/iptables-save
Red Hat/CentOS:
/sbin/service iptables save
Or
/etc/init.d/iptables save
To clear all the currently configured rules:
iptables -F
Rosetta Techonology | offensive security certified professional training 16