SSH Directory Permissions Settings
It is important to set the directory and file permissions for your ~/.ssh correctly.
Typically you want the permissions to be:
- .ssh directory: 700 (drwx——)
- public key (.pub file): 644 (-rw-r–r–)
- private key (id_rsa): 600 (-rw——-)
- lastly your home directory should not be writeable by the group or others (at most 755 (drwxr-xr-x)).
For example, to set this permissions do: $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/* $ chmod 644 ~/.ssh/*.pub $ ls -ltr ~/.ssh/
How To Use Github Tokens on the Command Line
GitHub’s access policy requires you to use tokens instead of username/password to update your repositories.
To adapt your existing local / cloned repos to token based auth: $ git remote remove origin $ git remote add origin https://[TOKEN]@github.com/[USER]/[REPO] $ git push Clone repos using token based authentication (non public repos) $ git clone https://[username]:[token]@github.com/[accountname]/[reponame]
Sending Email from the Command Line
mutt Examples
Sending just a file attachment (-a) and an empty message body: $ mutt -s “System logs” -a /opt/backup.sql – user@example.com < /dev/null Sending a message body using redirection: $ mutt -s “Email subject” test@example.com < email.html Sending a file attachment along with a message body: $ echo $message | mutt -s “Subject” -a attachment.txt – me@myemail.com
How to convert VirtualBox VDI to KVM qcow2
It is easy to convert a VirtualBox VDI image to a KVM qcow2 file. You have to use the RAW file format as an intermediate.
Make sure the VirtualBox machine is shutdown.
- Convert the VDI to a raw disk image. Note: VDIs are compressed and raw images are not, so you will need to leave enough disk space for entire uncompressed disk. $ VBoxManage clonehd –format RAW vm.vdi vm.img
- Then on your KVM host: $ qemu-img convert -f raw vm.img -O qcow2 vm.qcow2
How To Count All The Files Extension Recursively In Linux
To count all the files by file extension recursively on the command line $ find . -type f | sed -n ’s/..*.//p’ | sort | uniq -c 40 3g2 5 AVI 13 DS_Store 28 JPG 30 MOV 133 MP4 64 THM 1 docx 18 jpg 1 json 4 m3u 89 m4a 2 m4r 156 m4v 41 mkv 112 mov 38 mp3 587 mp4 1 nfo 2 osp 30 png 1 sh 4 srt 6 svg 10 torrent 6 txt 5 webm 10 zip
Untar a Tarball to a Remote Directory
Sometimes you may need to copy an entire directory structure to another system using the command line. Here is a quick way to do it using the tar command:
cat myfile.tgz | ssh user@host “tar xzf - -C /some/dir”
Gnome3 Menu Icons
To add your own menu icons to a GNOME3 environment check out this link: Desktop files: putting your application in the desktop menus
Getting Rid of ^M Line Endings in a Text File
If you have a text file that has funny looking ^M characters at the end of each line, in most cases, you have to get rid of them before they can be used. This is especially the case when you’ve copied or transferred a file from a Windows-based system to a *nix-based one. If these files are shell scripts meant to run on the *nix-based system they more often than not won’t work. There are various solutions to this problem.
Removing ^M Characters From Multiple Files
In my day job I find that I frequently need to remove those pesky ‘^M’ line endings from text files that are transferred from one system to the other. Most of the time it is just one file that needs to be fixed so going into vi and typing
:%s/^M//g
solves the problem, but on occasion I might be confronted with performing this process on multiple files and sometimes recursively through many subdirectories. When that happens it becomes necessary to bring out the “big guns” and do:
Get the Hash of a File on Different Operating Systems
Sometimes you just need to hash something. Here are some command lines to do just that.
Windows PowerShell:
Get-FileHash C:\path\to\file.iso -Algorithm [MD5|SHA1|SHA256|SHA384|SHA512|MACTripleDES|RIPEMD160]
(SHA256 is the default if the parameter is omitted)
Linux:
md5sum /path/to/file sha1sum /path/to/file sha256sum /path/to/file