This web site has been retired. Please follow my activities at pztrick.com.

pZtrick.com

the personal site of patrick paul

Patrick's Bash-isms

.bashrc & .bash_logout

ssh-agent keychain to persist your RSA keys until next re-boot

>> .bashrc #
1
2
3
4
5
6
7
# Start ssh-agent and keychain
# The `whoami` lines give the user and its sudo a separate ssh-agent process
[ `whoami` == 'root' ] && HOME=/root
/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/limberry-sh > /dev/null
[ `whoami` == 'root' ] && HOME=~
# End ssh-agent and keychain

tightvncserver to launch a tunnel’d VNC desktop while you are SSH’d in

>> .bashrc
1
2
3
4
5
6
7
# Load VNC at user login to permit SSH tunneling the desktop
if [ -n "$SSH_CONNECTION" ]
then
  /usr/bin/vncserver -geometry 1024x768 -depth 16 :$UID -localhost > /dev/null 2>&1
  echo -e "\n\e[1;33m*** Remote VNC desktop available via SSH tunnel at localhost:$(expr 5900 + $UID)\e[00m\n"
fi
# End VNC
>> .bash_logout
1
2
3
# Kill VNC at user logout and hide the output
/usr/bin/vncserver -kill :$UID > /dev/null 2>&1
# End VNC
>> .bash_aliases
1
2
3
# tightvncserver
alias svnc='vncserver -geometry 1024x768 -depth 16 :$UID -localhost '
alias kvnc='vncserver -kill :$UID'

Display the current working git branch in the terminal prompt

~/.bashrc
1
2
3
4
5
6
7
8
9
10
11
12
# add this branch near the top so it can be invoked downstream
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

# ...
# replace the matching code in the .bashrc that ships on Ubuntu
if [ "$color_prompt" = yes ]; then
    PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$(parse_git_branch)\$ "
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
Example Terminal Prompt
1
patrick@bangor-dome:~/code/secret-AI-robot(hotfix/addSelfDestruct)$ 

Stop CTRL+S from freezing terminal (Windows habits die hard, e.g. vim saving)

>> .bashrc
1
2
3
# disable CTRL+S freeze
stty ixany
stty ixoff -ixon

VNC remote usage:
ssh patrick@12.34.56.78 -p 12345 -L 6900:localhost:6900
vncviewer localhost:6900

.bash_aliases

trash-cli package

>> .bash_aliases
1
2
3
4
5
# trash-cli
alias tp='trash-put'
alias tl='trash-list | sort -r | less'
alias te='trash-empty 7'
alias rm='tp'

python & django development

>> .bash_aliases
1
2
3
# django
alias runserver='python manage.py runserver 0.0.0.0:8888'
alias rs='runserver'

~/.ssh/config Aliasing, Tunneling, and Multi-hops!

~/.ssh/config #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Host alias
 HostName 12.34.56.78
  [Port 12345]
  [User patrick]
  [LocalForward 6900 localhost:6900]

# Multi-hop SSH through intermediate host
# Adapted from: http://sshmenu.sourceforge.net/articles/transparent-mulithop.html
Host publiclyAccessibleHostInsideFirewall
  HostName not.firewalled.work.com

Host privateFirewalledHost1
  ProxyCommand ssh -q publiclyAccessibleHostInsideFirewall nc -q0 %h 22

Host privateFirewalledHost2
  ProxyCommand ssh -q publiclyAccessibleHostInsideFirewall nc -q0 %h 22

# The %h injects the Host alias from the preceding line

Usage: ssh alias scp alias:Documents/secret_plans.txt ~/stolen_plans.txt

bash terminal

ssh-copy-id "user@12.34.56.78 [-p 123]" [-i /path/id_rsa.pub]

scp 12.34.56.78:path/to/source.txt ~/local/destination.txt scp ~/local/source.txt user@12.34.56.78:path/destination.txt scp [-P 123] ~/source.txt user@12.34.57.68:destination.txt

Comments