Linux Shell

This page is an in-progress compilation of shell commands that I believe are useful. For a downloadable index of Bash/Shell scripts, click here.

You will need sudo privileges or be running as root with most of these commands

Hold Packages on Debian/Ubuntu

Prevent existing installed packages from being upgraded when you run apt-get upgrade by putting them on hold or unhold with both dpkg & apt.

DPKG


Put a package on hold

echo "package_name hold" | dpkg --set-selections

Remove the hold
echo "package_name install" | dpkg --set-selections

Display the status of all packages
dpkg --get-selections

Display the status of a single package
dpkg --get-selections | grep "package"

Purge config files left over from previously removed packages
dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge

Update available packages, upgrade packages, remove previously satisfied dependencies and their configs
apt-get update && apt-get upgrade -y; apt-get autoremove -y; dpkg --list | grep '^rc' | cut -d ' ' -f 3 | xargs dpkg --purge

APT


Hold a package

apt-mark hold package_name

Remove the hold
apt-mark unhold package_name

Remove and purge previously satisfied dependencies and their configs which are no longer required
apt-get autoremove -y; apt-get purge -y $(dpkg --list |grep '^rc' |awk '{print $2}')

Update available packages, upgrade packages, remove previously satisfied dependencies and their configs
apt-get update && apt-get upgrade -y; apt-get autoremove -y; apt-get purge -y $(dpkg --list |grep '^rc' |awk '{print $2}')

APTITUDE


Hold a package

aptitude hold package_name

Remove the hold
aptitude unhold package_name

List and Kill Screen Sessions

List all screen sessions

screen -list

Kill a screen session without being inside of it
screen -X -S [session # you want to kill] quit

File Manipulation

Copy one file into multiple files

Combine cat (retrieves the contents of a file) with tee (writes the content away to the files specified in the arguments)

cat original-file | tee file1 file2 file3 file4 file5 file6 blahblah >/dev/null

Networking

Count Local HTTPS Port Connections

watch -n 1 "netstat -n | awk '{print $4}' | grep :443 | wc -l"

Certificates

Export Linux SSL Cert to Windows

Related posts:
Convert x509/PEM SSL Certificate to PFX/P12 from Linux to Windows
Export SSL certificates from Windows to Linux

openssl pkcs12 -export -out "certificate.pfx" -inkey "privkey.pem" -in "cert.pem" -certfile chain.pem

OpenSSL Commands

Convert PEM

Convert PEM to DER:
`shell
openssl x509 -outform der -in certificate.pem -out certificate.der


<strong>Convert PEM to P7B:
</strong>

```shell
openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer

Convert PEM & Private Key to PFX/P12:

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

Convert full chained PEM & Private Key (Let’s Encrypt) to PFX/P12
(full chain = your cert + intermediate/root cert in a single file)

openssl pkcs12 -export -out sysinfo.io.pfx -inkey privkey.pem -in fullchain.pem

OpenSSL Convert DER

Convert DER to PEM:

openssl x509 -inform der -in certificate.der -out certificate.pem

OpenSSL Convert P7B

Convert P7B to PEM:

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

Convert P7B to PFX:

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer

OpenSSL Convert PFX

Convert PFX to PEM and Private Key

openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes

Remove Private key password

openssl rsa -in file.key -out file2.key

Enter the passphrase and [file2.key] is now the unprotected private key.

The output file:� [file2.key] should be unencrypted. To verify this open the file using a text editor (such as MS Notepad) and view the headers

Bash Profile

Reload ~/.bashrc

To reload your .bashrc/.bash_profile file you can do it with the source command without logging out and back in for changes to take effect

source ~/.bashrc
Disqus Comments Loading...