May
2
Nice one-liners from LJ Hack and /
Kyle Rankin writes a column for LInux Journal called Hack and /. He’s got a couple nice ssh-based one-liners in the June 2009 issue, which I’m listing here for myself and others to find later.
Put public key on remote server
This appends your public key to the authorized keys list on the remote server. This saves scp-ing it, ssh-ing, and appending it. Nice.
ssh user@server.whatever.tld "cat >> ~/.ssh/authorized_keys2" < ~/.ssh/id_rsa.pub
Image disk to file on remote server
This example assumes /dev/sda is the disk you want to image.
sudo dd if=/dev/sda | ssh user@server.whatever.tld “cat > /path/to/images/sda-image.img”
Clean, not necessarily quick. You can image directly to another disk if you ssh as root and cat to a device instead of a file.
Restore image from remote server
ssh user@server.whatever.tld "cat /path/to/images/sda-image.img" | sudo dd of=/dev/sda
As in the backup, you can do this directly from a device on the remote (I think).