Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. USERNAME="your username here"
  4. SFTPHOST="your sftp host"
  5. SFTPPORT=22 # or other port, if non-standard
  6.  
  7. # Create SSH key-pair for SFTP access
  8. # (creates pair with no passphrase)
  9. ssh-keygen -b 2048 -t rsa -C "$SFTPHOST" -N "" -f ~/.ssh/id_rsa.sftp
  10.  
  11. # Create authorized_keys file for upload
  12. ssh-keygen -e -f ~/.ssh/id_rsa.sftp.pub -m RFC4716 > ~/.ssh/authorized_keys.sftp
  13. chmod 600 ~/.ssh/authorized_keys.sftp
  14.  
  15. # Upload authorized_keys file to sftp
  16. # (this will prompt for a password)
  17. scp -P $SFTPPORT ~/.ssh/authorized_keys.sftp $USERNAME@$SFTPHOST:.ssh/authorized_keys
  18.  
  19. # Verify key-auth is working
  20. # (should log in without password prompt)
  21. sftp -o IdentityFile=~/.ssh/id_rsa.sftp -o Port=$SFTPPORT $USERNAME@$SFTPHOST
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement