Setup your own file paste service

Last modification on

Setup SSH authentication

Make sure to setup SSH public key authentication so you don't need to enter a password each time and have a more secure authentication.

For example in the file $HOME/.ssh/config:

Host codemadness
	Port 22
	IdentityFile ~/.ssh/codemadness/id_rsa

Of course also make sure to generate the private and public keys.

Shell alias

Make an alias or function in your shell config:

pastesrv() {
	ssh user@codemadness "cat > /your/www/publicdir/paste/$1"
	echo "$1"

This function reads any data from stdin and transfers the output securely via SSH and writes it to a file at the specified path. This path can be visible via HTTP, gopher or an other protocol. Then it writes the absolute URL to stdout, this URL can be copied to the clipboard and pasted anywhere like to an e-mail, IRC etc.

Usage and examples

To use it, here are some examples:

Create a patch of the last commit in the git repo and store it:

git format-patch --stdout HEAD^ | pastesrv 'somepatch.diff'

Create a screenshot of your current desktop and paste it:

xscreenshot | ff2png | pastesrv 'screenshot.png'

There are many other uses of course, use your imagination :)