Linux

Contents

Linux folder structure

Restart Apache service

sudo service apache2 restart

Reboot Computer

sudo reboot

Install VMware Tools

Update Ubuntu

apt-get update

Elevate session to root

sudo -i

Install MS RDP server

apt-get install xrdp

 

Install VNC viewer

Enable SSH server

Edit Sudoers file

Upgrade ubuntu

do-release-upgrade

Check for new versions of Ubuntu

do-release-upgrade -c

Find previous command history (case insensitve)

history | grep -i dns

Force quit process (named citrix)

ps aux | grep citrix
sudo kill (PID Number)

Reboot immediately

sudo reboot now

see all of the users on the machine

sudo cat /etc/passwd

Run command as other user

sudo -u otheruser -i /bin/bash

Users with bash access

sudo cat /etc/passwd | grep /bin/bash

 

Command reference

Function PowerShell/CMD Linux Comment
List files/directories ls, get-childitem, dir ls use ls -lha for best results
Get-Process
Get-Service
Stop-Computer, Restart-Computer
Get-Content
tail
head
ForEach
Get-Eventlog
 Get-Date
Uptime
Ipconfig ifconfig

 

install flash player

sudo apt-get install flashplugin-installer

open terminal

ctrl alt T

install curl

sudo apt-install curl

install youtube-dl

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
[/code]

install ffmpeg/ffprobe

sudo apt-get install -y libav-tools

Setup arduino COM port

ls -l /dev/ttyACM*
sudo usermod -a -G dialout <username>

Install Indicator Netspeed in Ubuntu

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install indicator-netspeed
(need to log off and on again)

Install CPU monitor/controls

Take a screenshot

printscreen

Get version of Oracle Solaris (SPARC)

cat /etc/release

Get Ubuntu version

lsb_release -a

Get Debian version

lsb_release -a

Get Centos Version

lsb_release -a

Get Raspian version (debian clone)

lsb_release -a

Get version of Oracle Solaris (non-SPARC)

cat /etc/release

 

Password Generator (Ubuntu)

sudo apt-get install pwgen

###############################
Generate 10 character password
###############################
pwgen 10                                                                                    
peiNuH9gae Irueshoh6e tiuPhei9so KailaiL8uM asu1Id7saL ohChooCh6c hoh4wahVah
ae5yie9Cu8 Ree0Aafa8S oyahy0aeSo Oheepe3ath Eewo4sheiy Loh9ve3eil tieQuel5oh

###############################
Generate 10 character password - without ambiguous characters
###############################
pwgen -B 10
quohthong3 Tiedahxae9 theiV9seir aeci3iesho meng7Nie9o ouchaix7ah asei3catah
fei4aem7Ee eex3uV7axi edood9Fe9a fuLee4Ahgh azoo3vae7j ahieY4jahx Taj9kai4ei

###############################
Generate 10 character password - without easy to remember components
###############################
pwgen -s 10
J222Rk2sHO 1nrfTW63Zl D1eSLqQgsV fSW7YOjnZy bjt35hqxKl ZBwpp19Ddu Ou0Dk2JD01
zkZ62yk8mx se2zerd9Tl 0ZNdOe01fE z5Ub6CmzpP ZxV6XFU5C1 h56TA4g7f1 O5OuUHVzhm

Bounce (take down and up) network adapter (Ubuntu)

(Run ifconfig first to find the adapter name)

sudo ifconfig eth0 down
sudo ifconfig eth0 up

Add new user (with shell access) – Solaris 10

#Elevate
sudo -i /bin/bash
#Create Account
useradd -g groupname -c "FirstName LastName" -s /bin/bash -m -d /export/home/username username
#Set Password
passwd username
#Force ^ Password to expire (so it makes them change it)
passwd -f username

Add new user (with NO shell access) – Solaris 10

#Elevate
sudo -i /bin/bash
#Create Account
useradd -g staff -c "FirstName LastName" -s /bin/false -m -d /export/home/username username
Note: check the -s flag (shell): /bin/false (can also use /bin/nologon, which gives a message)

Install Powershell

# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

# Register the Microsoft Ubuntu repository
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list

# Update apt-get
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
powershell

# Update PowerShell
sudo apt-get upgrade powershell

Show available Shells

 cat /etc/shells

Change default shell to PowerShell

sudo chsh username -s /usr/bin/powershell

Tunnel HTTP through SSH

#Requirement 
#   - SSH server (at home, for example)
#   - Linux host (at work, for example)
#
#Variables
#   - SSH server at home: HOMESERVER 
#   - HOMESERVER SSH Port: 22
#   - HOMESERVER SSH User: batfink
#   - Linux host at work: LINUXHOST
#   - Arbitrary proxy port: 8080
#
#Steps
#Do this stuff on your LINUXHOST
ssh -D 8080 batfink@HOMESERVER
#Do this stuff on your LINUXHOST too
#Open Firefox (or whatever) and navigate to proxy settings
#Select SOCKS proxy
#Server IP: 127.0.0.1
#Server Port: 8080
#Apply
#Browse internet from your HOMESERVER
#All this depends on your HOMESERVER having web access

Install java (to launch .jar files)

sudo apt-get install openjdk-9-jre

Mark a file as executable (eg .jar files)

sudo chmod +x /home/mike/Downloads/minecraft.jar

Join a domain (ubuntu)

Join a domain (CentOS)

Check SELinux status

sestatus

Disable Firewall

sudo service firewalld stop

Add new administrative user

Add new non-administrative user

Set Static IP

Change password

passwd

Set/change hostname

Reboot may be required to change the hostname

hostnamectl set-hostname <hostname>

Set DNS search domain/servers

List all user accounts

List is in order of account creation

cat /etc/passwd

List logged in/SSH’d users

w

Show installed memory/RAM

dmidecode -t 17 | grep "Size.*MB" | awk '{s+=$2} END {print s / 1024}'

Grep

here's a basic grep function if you want to search for a string in raw text files: 
grep -r -i string * 
 
-r = recursive so searches sub directories 
-i = searches uppercase and lowercase 
* searches all 
 can use it with regular expressions for hunting down IP addresses too: 
grep -r -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' * 

Server status one-liner

echo ""; echo "Server Status One-liner"; echo ""; echo "Storage: "; df -h | sed -n '2,2p' | awk '{print "Disk:",$3"/"$2,$5}'; df -i | sed -n '2,2p' | awk '{print "Inodes:",$3"/"$2,$5}'; echo ""; echo "Load Average: "; cat /proc/loadavg; echo -ne "Thread Count: "; cat /proc/cpuinfo | grep processor | wc -l; echo ""; echo "Usage: "; mpstat | tail -2; echo ""; echo "Memory: "; free -m; echo ""; echo "Vmstat: "; vmstat; echo ""; echo "Services: ";ps cax | grep mysqld > /dev/null; if [ $? -eq 0 ]; then echo "mysql is running"; else echo "mysql is not running"; fi; ps cax | grep httpd > /dev/null; if [ $? -eq 0 ]; then echo "httpd is running"; else echo "httpd is not running"; fi; ps cax | grep exim > /dev/null; if [ $? -eq 0 ]; then echo "exim is running"; else echo "exim is not running"; fi; ps cax | grep named > /dev/null; if [ $? -eq 0 ]; then echo "named is running"; else echo "named is not running(Are they root?)"; fi; ps cax | grep pure-ftpd > /dev/null; if [ $? -eq 0 ]; then echo "ftpd is running"; else echo "ftpd is not running"; fi; ps cax | grep courier > /dev/null; if [ $? -eq 0 ]; then echo "courier is running"; else echo "courier is not running"; fi; netstat -tunap | grep -v 0.0.0.0 | awk '/.*[0-9]+.[0-9]+.[0-9]+.[0-9].*/{gsub(/::ffff:/,"",$0);print $4"\t" $5 "\t" $6"\t" $7}' | awk -F"/" '{print $1"\t"$2}' > netstat.log; echo ""; echo "Connections:";echo "Number of connections to each port:";cat netstat.log | awk {'print $1'} | cut -d: -f 2 | sort | uniq -c | sort -nk 1;echo;echo "Number of connections from each IP:";cat netstat.log | awk {'print $2'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1;echo;echo "Number of instances of a particular IP connecting to particular port with connection states:";cat netstat.log | awk -F":" {'print $2 "\t" $3'} | awk {'print $1 "\t" $2 "\t" $4 "\t" $6'} | sort | uniq -c | sort -nk 1;echo;echo "SYN_RECV connections:";cat netstat.log | awk -F":" {'print $2 "\t" $3'} | awk {'print $1 "\t" $2 "\t" $4 "\t" $6'} | sort | uniq -c | sort -nk 1 | grep SYN_RECV; echo "Most CPU Intensive:"; ps auxf | sort -nr -k 3 | head -2;echo; echo "Most Memory Intensive:"; ps auxf | sort -nr -k 4 | head -2;  

CPU Intensive processes:

ps auxf | sort -nr -k 3 | head -5  

Memory Intensive processes:

ps auxf | sort -nr -k 4 | head -5

Connection by IPs:

netstat -tunap | grep -v 0.0.0.0 | awk ‘/.*[0-9]+.[0-9]+.[0-9]+.[0-9].*/{gsub(/::ffff:/,””,$0);print $4″\t” $5 “\t” $6″\t” $7}’ | awk -F”/” ‘{print $1″\t”$2}’ > netstat.log; echo “”; echo “Connections:”;echo “Number of connections to each port:”;cat netstat.log | awk {‘print $1’} | cut -d: -f 2 | sort | uniq -c | sort -nk 1;echo;echo “Number of connections from each IP:”;cat netstat.log | awk {‘print $2’} | cut -d: -f 1 | sort | uniq -c | sort -nk 1;echo;echo “Number of instances of a particular IP connecting to particular port with connection states:”;cat netstat.log | awk -F”:” {‘print $2 “\t” $3’} | awk {‘print $1 “\t” $2 “\t” $4 “\t” $6’} | sort | uniq -c | sort -nk 1;echo;echo “SYN_RECV connections:”;cat netstat.log | awk -F”:” {‘print $2 “\t” $3’} | awk {‘print $1 “\t” $2 “\t” $4 “\t” $6’} | sort | uniq -c | sort -nk 1 | grep SYN_RECV;

Connection States:

netstat -an | grep “:80” | awk ‘/tcp/ {print $6}’ | sort -nr | uniq -c

What Is Running?

pstree -a ps aux
top

Listening Services

netstat -nalp

CPU and RAM

free -m uptime top htop

Hardware

lspci dmidecode ethtool

IO Performances

iostat -kx 2 vmstat 2 10 mpstat 2 10 dstat –top-io –top-bio

Mount Points and Filesystems

mount cat /etc/fstab vgs pvs lvs df -h lsof +D /

Kernel, Interrupts and Network Usage

sysctl -a | grep … cat /proc/interrupts cat /proc/net/ip_conntrack /* may take some time on busy servers */ netstat ss -s
System Logs and Kernel Messages
dmesg less /var/log/messages less /var/log/secure less /var/log/auth

Cronjobs

ls /etc/cron* + cat for user in $(cat /etc/passwd | cut -f1 -d:); do crontab -l -u $user; done

Edit sudoers file

CD /etc/
sudo visudo

Get root access for the entire session

Sudo –i

Vi shortcuts

Insert/Edit file: i
Stop editing file: Esc
Quit: :q

Search for multiple strings in a file in UNIX

cat filename.log | egrep “string1|string2|string3”

Search for strings inside a compressed file in UNIX

cat filename.tar.gz | zgrep string

Set subnet mask/netmask/mask

ifconfig eth0 netmask 255.25.255.0

Show Uptime

Ping broadcast/gateway address

ifconfig eth0 10.1.7.13 netmask 255.255.255.0 up