Basic : All about linux

In this section we learn about linux file-system , basics commands , services and some tools

Linux Filesystem

In kali linux there are different files in " / " root directory each of them contains different types of files..


  /bin      # basic programs (ls, cd, cat, etc.)
  /sbin    # system programs (fdisk, mkfs, sysctl, etc)
  /etc     # configuration files like "paswd, shadow , hosts, crontab"
  /tmp     # temporary files (typically deleted on boot)
  /usr/bin   # applications (apt, ncat, nmap, etc.)
  /usr/share   # application support and data files

There are many other directory present as well , but these are some of basics and important directory that we should look before move in.

Basic Linux Commands

Its important that we know basics commands of linux because 95% of the time we spend in terminal or shell .

i am running as root, so i didn't use sudo before any command. if you are using low priv account make sure to use sudo.

Man page

  • man page is a manual for any command we used, we can read about their switches and descriptions about that commands eg. ( man ls )


man passwd    # show the uses of password command

man -k passwd # -k  search for keyword (like apropos) , show possible command related with passwd 

apropos passwd  # apropos will search possible list of man page for a possible match based on keyword.

Listing Files


ls

ls /usr/share/wordlists/*    # display all items in wordlists dir , we use *  wildcard.

ls -la    # -l for listing format  and -a for hidden 

ls -R     # recursive search 

Moving Around


pwd         # print the current working directory.

cd /        # go to root directory where all files start.

cd ~        # go to users home directory.

cd /usr/share/wordlist     # we change the directory to wordlist .

cd ..        # go one directory back and now we are at "share".

cd -     # same use go back one directory.

Creating Directory

  • while making directory remember linux is case sensitive.


mkdir notes        # it will create a directory named as "notes"

mkdir new notes     # it will create two new directory new and notes 

mkdir "new notes"    # it will create one new dir "new notes"

rmdir notes     # it will remove notes dir

rm -rf notes     # it will remove notes forcefully


mkdir "new dir"    # it will create new dir named as "new dir"

cd new\ dir/    # now we are in "new dir" dir, here \  backslash is used for ignoring the empity space b/q new and dir .

mkdir -p notes{maths,phy,chem}    # here it create dir notes and inside it create 3 new dir named as maths , phy ,chem .

Finding Files in kali system

  • which

which $PATH     # it will show the path environment for given name

which python     # show the dir where python is present

  • locate


sudo updatedb     # update the databse before running the commands.

locate *.nse    # find all files with .nse extension 

locate sbd.exe    # find file sbd.exe
  • find

    • Find is very use-full command when it comes to finding file with different parameters, read man page for find command.


find / -name *.sbd    # it will find the file form / dir with name *.sbd .

find / -perm -u=s -type f 2>/dev/null    # find file form / dir with -perm permisson , -u=s denotes look for files that are owned by the root user -type is type f denote looking for regular files , 2 denotes stander error redirected to /dev/null  

Managing kali Services

  • kali comes with default Pre-installed services such as ssh , http, mysql etc.

  • we can use this services according with our's need.

SSH Service

  • we can use systemctl or service command for running and stopping the services.


systemctl start ssh     # running the ssh    

systemctl status ssh     # status of ssh

systemctl stop ssh    # stoping 

service ssh start     # same as previous 

systemctl enable ssh     # if we want that ssh automatic start with boot then we enable the service with enable switch , same as disable 

example

 
                                                                                                                                                                                                                                                                   
┌──(root💀rio)-[~]
└─# service ssh start    
                                                                                                                                      
┌──(root💀rio)-[~]
└─# service ssh status
 ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2022-08-09 06:18:32 IST; 4s ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 98046 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
   Main PID: 98047 (sshd)
      Tasks: 1 (limit: 14118)
     Memory: 1.5M
        CPU: 23ms
     CGroup: /system.slice/ssh.service
             └─98047 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"

Aug 09 06:18:32 rio systemd[1]: Starting OpenBSD Secure Shell server...
Aug 09 06:18:32 rio sshd[98047]: Server listening on 0.0.0.0 port 22.
Aug 09 06:18:32 rio sshd[98047]: Server listening on :: port 22.
Aug 09 06:18:32 rio systemd[1]: Started OpenBSD Secure Shell server.
                                                                                                                                      
┌──(root💀rio)-[~]
└─# ss -antlp | grep sshd             
LISTEN 0      128               0.0.0.0:22        0.0.0.0:*    users:(("sshd",pid=98047,fd=3))
LISTEN 0      128                  [::]:22           [::]:*    users:(("sshd",pid=98047,fd=4))
                                                                                                                                      
┌──(root💀rio)-[~]
└─# service ssh stop     

HTTP Service

  • it can be run as systemctl or service command.

  • same goes to enable and disable.

  • HTTP Service is a web server that loads at port 80 on our local-host IP its dir is /var/www/html where it host.

  • apache is a webserver that comes pre-installed in kali so we are using apache , we can user nginx or python as well.

  • we can use it as a web-server for downloading files at Victum Machine.

# for apache
service apache2 start 
service apache2 status
service apache2 stop

systemctl start apache2    # for start
systemctl enable apache2    # for enable, it will automatic start afte every reboot
systemctl stop apache2        # for stop
systemctl disable apache2        # for changing conf. of apache

systemctl list-unit-files    # for checking the list of enable & diable services..

# for nginx
service nginx start 
service nginx stop

example


┌──(root💀rio)-[~]
└─# service apache2 start 
                                                                                                                                      
┌──(root💀rio)-[~]
└─# service apache2 status
 apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2022-08-09 06:37:07 IST; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 98385 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 98402 (apache2)
      Tasks: 6 (limit: 14118)
     Memory: 18.5M
        CPU: 95ms
     CGroup: /system.slice/apache2.service
             ├─98402 /usr/sbin/apache2 -k start
             ├─98404 /usr/sbin/apache2 -k start
             ├─98405 /usr/sbin/apache2 -k start
             ├─98406 /usr/sbin/apache2 -k start
             ├─98407 /usr/sbin/apache2 -k start
             └─98408 /usr/sbin/apache2 -k start

Aug 09 06:37:07 rio systemd[1]: Starting The Apache HTTP Server...
Aug 09 06:37:07 rio apachectl[98401]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using >
Aug 09 06:37:07 rio systemd[1]: Started The Apache HTTP Server.
                                                                                                                                      
┌──(root💀rio)-[~]
└─# service apache2 stop  

Searching, Installing, and removing Tools

apt update

  • apt update command will update the list of available packages, including information related to their versions, descriptions, etc so that we can upgrade the system.

apt update 

apt upgrade

  • After the APT database has been updated, we can upgrade the installed packages and core system to the latest versions using the apt upgrade command.

apt upgrade -y     # upgrade the full package

apt upgrade metsaploit-framework    # upgrade single package

apt-cache and apt show

  • The apt-cache search command displays much of the information stored in the internal cached package database.

  • apt show display the information of the package

apt-cache search pure-ftpd

apt show pure-ftpd

example

┌──(root💀rio)-[~]
└─# apt-cache search pure-ftpd
ftpd - File Transfer Protocol (FTP) server
mysqmail-pure-ftpd-logger - real-time logging system in MySQL - Pure-FTPd traffic-logger
pure-ftpd - Secure and efficient FTP server
pure-ftpd-common - Pure-FTPd FTP server (Common Files)
pure-ftpd-ldap - Secure and efficient FTP server with LDAP user authentication
pure-ftpd-mysql - Secure and efficient FTP server with MySQL user authentication
pure-ftpd-postgresql - Secure and efficient FTP server with PostgreSQL user authentication
resource-agents - Cluster Resource Agents
                                                                                                                                      
┌──(root💀rio)-[~]
└─# apt show pure-ftpd        
Package: pure-ftpd
Version: 1.0.50-2.1+b2
Priority: optional
Section: net
Source: pure-ftpd (1.0.50-2.1)
Maintainer: Stefan Hornburg (Racke) <racke@linuxia.de>
Installed-Size: 670 kB
Provides: ftp-server
Depends: lsb-base (>= 3.2-14), openbsd-inetd | inet-superserver, pure-ftpd-common (= 1.0.50-2.1), libc6 (>= 2.33), libcap2 (>= 1:2.10), libcrypt1 (>= 1:4.1.0), libpam0g (>= 0.99.7.1), libsodium23 (>= 1.0.10), libssl3 (>= 3.0.0)
Conflicts: ftp-server
Replaces: ftp-server
Homepage: https://www.pureftpd.org/project/pure-ftpd/
Tag: interface::daemon, network::server, protocol::ftp, protocol::ssl,
 role::program, works-with::file
Download-Size: 173 kB
APT-Sources: https://mirror.anigil.com/kali kali-rolling/main amd64 Packages
Description: Secure and efficient FTP server
 Free, secure, production-quality and standard-conformant FTP server.
 Features include chrooted home directories,
 virtual domains, built-in 'ls', anti-warez system, configurable ports for
 passive downloads, FXP protocol, bandwidth throttling, ratios,
 fortune files, Apache-like log files, fast standalone mode, atomic uploads,
 text / HTML / XML real-time status report, virtual users, virtual quotas,
 privilege separation, SSL/TLS and more.

apt install

  • apt install will install the package

apt install pure-ftpd    # install package pure-ftpd

apt-remove --purge

apt remove pure-ftpd    # remove this package 

apt purge --purge pure-ftpd    # this option remove the package with no leftover.

dpkg

  • dpkg used to install offline package

dpkg -i  man-db_2.7.0.2-5_amd64.deb    # -i install this package 

dpkg -r man-db_2.7.0.2-5_amd64.deb     # -r remove the package 

misc commands


who                  # show users info in details
whoami            # show your current user
uname -a    # display kernal information
         
su kali                   # for swithching to kali user
su root                  # for switching root user
adduser jhon        # it wiil add user like jhon
su jhon                 # for switching to jhon user
deluser jhon         # it will del user jhon 

sudo shutdown now -r         #  for restsrt
sudo shutdown now -c         #  cancel the previous shoutdown
sudo shutdown now            #  system shutdown
poweroff                     # power off system
poweroff -f                  # forcefully
reboot                       # reboot system 
reboot -f                    # forcefully

date                                    # display date 
date --set ='10 Feb 2017 11:13'         #  for change date
cal                                     # for  calander

yes              # it will loop 
yes sahil        # loop sahil   ,  [ctrl] + c       to terminate

factor 1024            # helps to do maths factor 

Searching, Installing, and Removing tools

Last updated