Examine x509 Certificate
A quick way to examine a certificate in plain text…
openssl x509 -text -in cert.pem
Convert Separate Key/Cert Files to a PFX
The reverse of the process of extracting the key/certs from a PFX can be achieved via…
openssl pkcs12 -export -in [certificate.crt] -inkey [private.key] -out [package.pfx]
Recover MySQL Root Password
To recover the password for the root account on a MySQL server use the following steps…
(Essentially, it can be done by restarting the daemon without the grant tables)
1. Stop the current mysql process
# /etc/init.d/mysql stop
2. Start the daemon without the grant tables
# mysqld_safe —skip-grant-tables &
3. Login to mysql as the root user … it will have a blank password
mysql> use mysql;
mysql> update user set password=PASSWORD(“newPassword”) where User=’root’;
mysql> flush privileges;
mysql> quit
5. Stop & restart the daemon
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
Content-Disposition Header
In situations where you want a file linked to from within a website to present a ‘Save As’ dialog rather than simply displaying the content … you can inject a Content-Disposition header into the HTTP connection to prompt the browser to do so. I recently had a situation where I was linking to an uncommon file extension through a reverse-proxy and Internet Explorer wanted to include extra URI information in the ‘Save As’ file name. You can force the saved file name with this header as well.
In PHP, the header is introduced as follows…
header(‘Content-type: text/plain’);
header(‘Content-Disposition: attachment; filename=myfile.txt’);
Upper To Lower To Upper Case Command Line
Nice trick to pipe command line data through to convert it’s alpha characters to upper or lower case.
From UPPER to lower…
tr [:upper:][:lower:]
From lower to UPPER…
tr [:lower:][:upper:]
For example…
ls /directory | tr [:lower:][:upper:] | sort
Remote Reboot Windows XP
Using the Remote Desktop client to connect to a Windows XP system will not provide you with the option to reboot or restart the remote machine. This can be done from the command line however. Open a command prompt (Start->Run->Cmd.exe) and use the command…
shutdown -r -t 0
… to open a gui interface to manage the reboot …
shutdown -i
Enable Syntax Highlighting In VIM (vi) In Mac OSX
To enable the syntax highlight feature of Vim (vi) on Mac OSX, edit the /usr/share/vim/vimrc file and add the “syntax on” config. To do this from Terminal.app …
sudo vi /usr/share/vim/vimrc
…add a new line, “syntax on” and then save and close the file.
Mount ISO (.iso) In Linux
To mount an ISO (.iso) on a Linux system…
mount -t iso9660 -o ro,loop /path/to/file.iso /path/to/mount/point
In many cases you will not have to specify the “-t iso9660” as most Linux distributions will auto detect that. The “ro” in the “-o ro,loop” tells this system to mount the .iso read only.
Convert DMG To ISO & ISO to DMG
To convert a Mac .dmg to a .iso image file, open Terminal.app and then run the following command…
hdiutil convert /path/to/filename.dmg -format UDTO -o /path/to/filename.iso
To convert a .iso image file to a Mac .dmg, also in Terminal.app run the following command…
hdiutil convert /path/to/filename.iso -format UDRW -o /path/to/filename.dmg
Strip Leading Zeros In Shell
Nice trick to strip leading zeros from an IP address at the command line (it turn 002.203.017.001 to 2.203.17.1)…
echo 002.203.017.001 | awk -F “.” ‘{print int($1)”.”int($2)”.”int($3)”.”int($4)}’