Index of Commonly Used Commands

Quick reference for useful day-to-day commands


scp

Local => Remote
$ scp local_file.txt -i path_to_secret.pem remote_username@10.10.0.2:/remote/directory
Remote => Local
$ scp -i path_to_secret.pem remote_username@10.10.0.2:/remote/file.txt /local/directory
Remote => Remote
$ scp user1@host_1.com:/files/file.txt user2@host_2.com:/files

ssh

Generate SSH Key
$ ssh-keygen -t rsa -b 4096 -C "wes@example.com"
SSH Config (macOS)
# ~/.ssh/config

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa
Add SSH private key to ssh-agent and store passphrase in keychain
$ ssh-add -K ~/.ssh/id_rsa
Background SSH session with port forwarding. This is useful for running remote jupyter notebooks, for example.
# ~/.ssh/config

Host foo
  Hostname [public ipv4]
  User [user]
  IdentityFile [path_to_secret.pem]
$ ssh -NfL 9999:localhost:8888 foo

psql

useful meta-commands
$ \l # list databases
$ \c orders # switch to database 'orders'
$ \dt # list tables
$ \conninfo # echo connection info
$ \des # list foreign servers
$ \dew # list foreign data wrappers
$ \? # get meta-command help
connection params
$ psql -h [host] -p [port] -d [db] -U [user]

chmod

Value rwx Binary
7 rwx 111
6 rw- 110
5 r-x 101
4 r-- 100
3 -wx 011
2 -w- 010
1 --x 001
0 --- 000

Example usage

$ chmod 400 [file] # 'set read only for User class, no permissions for Group or Others'

git

Reference for less-often used git commands that have come in handy

Determine if commit is in branch
$ git branch --contains [commit_id]