Setup your own file paste service

Last modification on 2018-03-10

This article describes how you can setup your own secure file paste service:

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.

Make an alias or function in your shell config:

pastesrv() {
	ssh user@codemadness "cat > /home/www/domains/$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.

To use it, here are some examples:

Create a patch of the last commit in the git repo and stored 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 :)