Posts Tagged ‘Shell’

Don’t be a Tw@t – Use At!

Sigh today I made a schoolboy error – making config changes to a live firewall on a remote server without giving myself any kind of safety net! Anyway, this is an example of where you should really use something like the at command to bail you out should anything go wrong: get the current system […]

Check how old a Linux password is using chage

I came across a command today that I’ve never really had a use for before.  chage can be used to check when a password was last modified and also shows any password expiration rules etc.  It can also be used to implement password expiration. A very useful tool if password policies are required, although PAM […]

Delete a file older than X days using mtime

List files older than 5 days: find ./ -mtime +5 To count all files older than 5 days find ./ -mtime +5 |wc -l To move files to an archive directory: find ./ -mtime +5 -exec mv {} /var/archive \; -print To delete the files find ./ -mtime +5 -exec rm {} \; -print

Prevent brute force attacks using SSHBlack

SSHBlack is a very useful script which monitors the system logs for repeated failed logins and then blocks the source IP.  This can pretty much negate basic brute force attacks.  There are plenty of similar other applications such as BruteLock, but I think SSHBlack works well.  The following is a very handy article which shows […]

Postfix queue administration

Although I’ve used many MTA’s before, I’m new to postfix so here’s a few handy commands to note: List the mail queue: postqueue -p or mailq Delete a single message: postsuper -d 4C63F2300BA

Find broken symlinks

Quick tip to find broken symlinks in the filesystem: find -L . -type l

Useful Linux find examples

The Linux/Unix find command can be used to do a lot more than find strings. Here’s a few very handy commands I’ve put together over the years: Recursively chmod files and folders to something sensible: find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; Find files […]

Debian / Ubuntu package Management

You can search for a package by packagename or a word within the package description: apt-cache search apache2 apt-cache search “Apache ” You can also search by a file that is within the package: apt-file search apache2.conf Show package information: apt-cache show apache2 or apt-cache showpkg apache2 List files in a package: apt-file list apache2 […]

Check RAM type without opening server

You can use dmidecode in Linux to check various hardware specs such as CPU / memory without having to physically open or power down the server. For example to see the RAM needed: dmidecode –type memory SMBIOS 2.5 present.

Ping an entire network / netblock

You can use fping to ping a netblock to see which hosts are alive: fping -g 192.168.0.0/24 You could also put ping into a loop, but the output is less than useful: for i in {1..254}; do ping -c1 192.168.1.$i; done nmap is also a handy solution and can provide much more host information if […]