Skip to content

Latest commit

 

History

History
113 lines (84 loc) · 5.03 KB

Readme.md

File metadata and controls

113 lines (84 loc) · 5.03 KB

Description

This repository contains various scripts comprising of various techniques and linux commands (awk, grep,egrep, ping, usermod, sed, ps, kill, useradd):

  • central-logger.bash >>>>>> This script will log messages related to only defined keywords like: "refused|invalid|error|fail|lost|shut|down|offline"
  • check-dir.bash >>>>>> This script will find directories without users or unknown user
  • check-file-system.bash >>>>>> This script will check for disk space
  • check-files.bash >>>>>> This script will check whether given files are present in the system
  • copy-files-to-remote.bash >>>>>> This script will copy files to remote hosts
  • disable-users-for.bash >>>>>> This script will disable inactive user accounts using for loop
  • disable-users-xargs.bash >>>>>> This script will disable inactive user accounts with xargs
  • inventory-add-record.bash >>>>>> This system will add a system inventory to the database file
  • inventory-delete-record.bash >>>>>> This script will delete system from inventory database file
  • kill-process.bash >>>>>> This script will find dead or zombie process and kill them
  • list-users-by-input.bash >>>>>> This script will list users logged in by user input of date
  • list-users.bash >>>>>> This script will list users logged in today
  • log-alert.bash >>>>>> This script will send an email to administrator
  • rename-file.bash >>>>>> Rename files ending with .txt
  • total-num-files.bash >>>>>> This script will verify total no. of files
  • user-add-automation.bash >>>>>> This script will check if the user already exists, if not will create along with description specified by -c, and userid is specified by -u


Notes

Cron Job

  • Description: A cron job is a automated servvice in linux that you can use to run a script in schedule, Moreover you can notiy someone using email/sendmail
  • Usage: crontab -e [to edit user's crontab]
  • Values provided for [m h dom mon dow command] (minute (m), hour (h), day of month (dom), month (mon), and day of week (dow))
  • You might need to add yourself to the crontab user group using: usermod -a -G crontab (username)

Extra Notes

  • /etc/passwd contains users registerd on the system which can perform actions and have a shell assosciated to them
  • There are 7 file types in linux
  • Log directory: /var/log
  • Types of logs: boot, chronyd, cron, maillog, secure, messages, httpd

Commands

  • scp: Command to securely transfer files between servers "scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
  • last: lists users who had logged in earlier
  • awk: returns particular columns
  • To log a message to the syslog: logger -t error "Hey therea"
  • To run a command in the background you use nohup and &
  • In conditions, if the variable will ahve a digit or integer value we use -eq, for charachters we use ==
  • usermod -L will disable the users
  • The command used to check processes: ps -ef
  • sed command is used to perform manipulation on the data within a file that appears as output, it doesn't change the original file. For example: sed 's/lenny/gan/g' filename (this will replace lenny everywhere with gan), to change in the original file add -i flag to the command. Another example: sed -i '/^$/d' filename (Delete empty lines in the original file also)

Wild cards

      • represents zero or more charachters
  • ? - represents a single character, example: ls -l ?abcd.txt
  • [] - represents a range of characters, example: touch file[1..9].txt, ls -l [cd] //either c or d

Soft Links and Hard links

  • Inode: Pointer o number of a file on the hard disk
  • SoftLink: Link will be removed if file is removed or renamed (command: ln -s)
  • Hard Link: Deleting or renaming or moving the original file will not affect the hard link (command: ln)*

File Ownership

  • chown changes the ownership of a file
  • chgrp changes the group pwnership of a file
  • Recurrsiove ownership change -R

Combining and splitting files

  • cat file1 file2 file3 > file4
  • split file4
  • split -l 300 file.txt childfile : will split file.txt into 300 lines per file and output to childfilea, childfileab and childfileabc

Utility Commands

  • date
  • uptime
  • hostname
  • unmae
  • which
  • cal
  • bc

Terminal Commands

  • script: It stores terminal activities in a log file that can be named by a user, when a nme is not provided, the default file name typescript is used
  • exit
  • clear

Aliases

  • alias dir="ls -l | grep ^d"
  • alias tell="whoami; hostname"

NIC bonding

  • Network Interface Card bonding
  • Aggregation of multiple NIC into a single interface bond

Linux OS Hardening

  • User Account
  • User account
  • Stop Un-wanted services
  • Check on listening ports
  • Secure SSh Configuration
  • Enable SELinux
  • Change Listening services Port Numbers
  • Keep your OS up to date (Security Patches