Skip to content

Instantly share code, notes, and snippets.

View phx's full-sized avatar

phoenix phx

View GitHub Profile
@oanhnn
oanhnn / using-multiple-github-accounts-with-ssh-keys.md
Last active July 22, 2024 13:33
Using multiple github accounts with ssh keys

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@phx
phx / sed multiline replace
Created June 20, 2013 07:08
sed work in progress
#!/bin/bash
cat "hello.txt" | sed -E '/src=".+"/ {
r boobs.txt
d
}
'
@phx
phx / remote auto ssh key exchange
Created June 13, 2013 22:59
will automatically exchange ssh keys with remote server, allowing automatic future password-less access to the remote location from current location. edit as needed if remote location doesn't run sshd on default port.
#!/bin/bash
printf "enter username@ip-address: " ; read UIP ; ssh $UIP "mkdir .ssh 2>/dev/null ; echo $(cat $HOME/.ssh/id_rsa.pub) >>.ssh/authorized_keys ; chmod 700 .ssh ; chmod 600 .ssh/authorized_keys" ; echo "hostname=$(ssh $UIP hostname)"
@phx
phx / base64
Created June 13, 2013 04:39
encode image to base64 text string using native openssl package in osx. encoding with this method is more widely-available than the regular base64 package, because it doesn't first require installing xcode or building gnu coreutils from source.
#!/bin/bash
openssl base64 -in pudding.png > pudding.txt
@phx
phx / i++
Created June 13, 2013 03:15
increment a variable inside a for loop to rename all text files that start with a certain string.
#!/bin/bash
for files in old*.txt
do
((i++))
mv $files $(echo $files | sed -E 's/[0-9]+\.txt//')OLDOLD$i.txt
done