SSH Pubkey Setup In One Command

Monday, February 14, 2005.

Transfer your ssh public key to a remote host, for passwordless logins, in one command:

ssh < "$key" "$@" '
  cat > $HOME/authorized_keys && 
  mkdir -p .ssh &&
  cat $HOME/authorized_keys >> $HOME/.ssh/authorized_keys &&
  rm -f $HOME/authorized_keys &&
  chmod 0700 .ssh &&
  chmod 0600 $HOME/.ssh/authorized_keys'

Note that newer versions of ssh now have ssh-copy-id(1).

Posted by Alan on Monday, February 14, 2005.