Category: BASH

Find and Kill All Processes One Liner

Brilliant – where you need it – like when you accidentally try to open 8000 html files at once with your browser. sudo kill $(ps aux | grep ‘iceweasel’ | awk ‘{print $2}’) credit for Find and Kill All Processes One Liner – bash using grep and awk

How To Block Traffic by Country using IPtables

http://www.linuxstall.com/block-country-iptables/ http://www.ipdeny.com/ipblocks/ http://www.ipdeny.com/ipblocks/data/countries/ #!/bin/bash # country codes ISO="cn it kr br ru tw af sa iq sy tr ua in jp id at ro pl bg vn hk ve th mx co ar ir cz ph eg pk" # set path IPT=/sbin/iptables WGET=/usr/bin/wget EGREP=/bin/egrep $IPT-save -c > /home/iptables/iptables_bak_$(/bin/date +\%Y\%m\%d\%H\%M\%S).txt SPAMLIST="countrydrop" ZONEROOT="/root/iptables" DLROOT="http://www.ipdeny.com/ipblocks/data/countries" cleanOldRules(){ $IPT -F $IPT -X $IPT -t nat...

Block All Traffic to Your New Remote Server

I block all traffic to a new server while I setup users and environment using Netfilter AKA iptables. Nothing else gets in or out of the box but me. This requires 2 scripts actually. One to close the machine to all other IPs but mine, and one to “unblock”. You need to unblock while installing other software, re. LAMP, when...

Change Default Editor at System Level

In a terminal type sudo apt-get install vim sudo update-alternatives –config editor Follow the instructions to choose vim.basic – your display will vary Debian Ubuntu Change Default Editor Nano VI Gedit at System Level sudo vi /etc/vim/vimrc uncomment line 20 – syntax on logout & login

Handy Linux Directory Rules

Linux Directory Rules rsync -vaz ~/qwerty ~/mydir CREATES a /qwerty directory under the ~/mydir directory COPIES the DIRECTORY and CONTENTS of the ~/qwerty directory into this newly created directory Without a trailing slash / it means “COPY THE DIRECTORY” rsync -vaz ~/qwerty/ ~/mydir Does NOT CREATE /qwerty directory COPIES the CONTENTS of the ~/qwerty directory to the mydir directory A...

Some Bash Scripts to Manage Remote Server

Script to Update and Upgrade #! /bin/bash chmod 700 /usr/bin/apt-get chmod 700 /usr/bin/aptitude chmod 700 /usr/bin/dpkg swapoff -a chown username:username /home/username/* chmod 700 /home/username/* apt-get update && apt-get upgrade –show-upgraded -y Script to End session and Harden some critical files #! /bin/bash swapon -a chmod 000 /usr/bin/apt-get chmod 000 /usr/bin/aptitude chmod 000 /usr/bin/dpkg find /home/username/ -size 0 -exec rm '{}'...

Set BASH as Default Shell

Enter at the prompt $ bash If command not found error, install BASH # pkg_add -r -v bash Now find where BASH is installed $ which bash You should see (Ubuntu) /bin/bash Change shell to BASH $ chsh -s /bin/bash username username is your User Name You should see: Password: Provide your login password You’ll need to logout (exit) and...

Create User on Debian

Users and Groups Users are located in /etc/passwd Groups are located in /etc/group The administrative ROOT account is disabled by default in Ubuntu . If you wish to enable the root account, simply give it a password by typing sudo passwd To disable the root account sudo passwd -l root The initial user created by the Ubuntu installer is a...

Could not chdir to home directory home Permission denied

This one has caught me a couple times and I keep forgetting how simple it is to solve. When you create a new user and then login as the new user, you get this message: Could not chdir to home directory /home/user: Permission denied -bash: /home/user .bash_profile: Permission denied And you find that you are not (and not able to...

-bash: sudo: command not found

When you see this error message -bash: sudo: command not found su apt-get install sudo adduser username sudo apt-get install locales locale-gen en_US.UTF-8