#Run iostat to get the average cpu usage every 10 seconds for 10 times:iostat -x 10 10 >> /home/<user>/iostat.out.$(date +"%Y-%m-%d")
#Run dstat to get cpu stats for cpus 1, 3 and the total:dstat -C 0,3,total
#Run iostat to get the average cpu usage every 10 seconds for 10 times:iostat -x 10 10 >> /home/<user>/iostat.out.$(date +"%Y-%m-%d")
#Run dstat to get cpu stats for cpus 1, 3 and the total:dstat -C 0,3,total
To run top in batch mode (updating every 3 seconds) and write it to a file in my directorytop -b -d 10 -n 3 >> /home/<user>/top-file
Watch disk usage updating every 3 seconds:watch -d -n 3 'df -h'
To delete lines 4-12 in Vim::4,12 d
To replace the word foo with the word bar starting at the line where the cursor is through the end of the file::.,$s/foo/bar/
To remove the spaces in the middle of a pip list output line and replace it with == so it can be used to install (if you have to recreate your pyenv):
:%s/([^ ]+ ) +/\1==/g
:%s/ ==/==/
To remove == and everything after from a pip list so that pip will install the newest version:
:%s/==.*//
To reformat a paragraph in vim:Use <CTRL-J> to join all lines in the paragraph
:gq
To remove all commented and blank lines from a file::g/\v^(#|$)/d
Tar and encrypt:
tar cz <dir>/ | openssl enc -aes-256-cbc -pbkdf2 -iter 10000 -e > out.tar.gz.enc
Decrypt:openssl enc -aes-256-cbc -d -in out.tar.gz.enc | tar xz
To determine which SSL Ciphers your site supports, you can run this (rather intrusive) nmap command:nmap -sV --script ssl-enum-ciphers -p 443 <hostname>
From the command line on the server, you can run this command:sslscan -show-ciphers <hostname>:443
Since RedHat/Ubuntu/Debian’s /proc/cpuinfo
has a separate entry for each CPU core, you can use this command to count them:cat /proc/cpuinfo | grep processor | wc -l
To convert a UTF-8 encoded file to UTF-16, you can use iconv
on the command line:iconv -f utf-8 -t utf-16 oldfile > newfile
To connect to MySQL through a tunnel
Open a tunnel on your local machine listening on localhost:3307 and forwarding everything to the mysqlserver server on port 3306, and doing it all via the ssh service on the gateway machine.
ssh -L 3307:domain.name.of.mysqlserver:3306 username@domain.name.of.gatewayserver
Now start mysql connecting to localhost on the port that you are tunneling mysql from the mysql server.
mysql -u username -p -h 127.0.0.1 -P 3307 databasename
mysql assumes it’s connecting to localhost, but on a non-standard port. In fact, the connection is being made securely to the remote mysql server, via the gateway machine and the local “mouth” of the ssh tunnel on your own machine.
—————————————————
tunnel all outbound E-mail traffic back to my personal server to avoid having to change SMTP servers when I am behind firewalls.
ssh -f user@personal-server.com -L 2000:personal-server.com:25 -N
—————————————————-
to send my Google Talk traffic encrypted through the firewall back to my server at home and then out to Google.
ssh -f -L 3000:talk.google.com:5222 home -N
—————————————————
If you are using an updated openssh package and suddenly can’t connect to sites that you could before the update, you can add an option to your .ssh/config file (create it if you don’t have one).
If you see this error:
Unable to negotiate with 127.0.0.1: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1
add this:
Host somehost.example.org
KexAlgorithms +diffie-hellman-group1-sha1
If you see this error:
Unable to negotiate with 127.0.0.1: no matching host key type found.
Their offer: ssh-dss
add this instead:
Host somehost.example.org
HostkeyAlgorithms ssh-dss
There are command line versions of these as well.
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@127.0.0.1
ssh -oHostKeyAlgorithms=+ssh-dss user@127.0.0.1
Note: It is worth noting that these weaker cyphers were removed from the configuration for a reason. If there is another way to connect without enabling them, it might be worth considering.