Skip to content

Instantly share code, notes, and snippets.

@jbwl
Forked from angrychimp/sftp-setup-ssh-keys.sh
Created November 23, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbwl/13a2dc05ac98b057332ed0f5803940fe to your computer and use it in GitHub Desktop.
Save jbwl/13a2dc05ac98b057332ed0f5803940fe to your computer and use it in GitHub Desktop.
Setting up SSH keys for key-auth with ProFTPd (w/ SFTP module)
#!/bin/bash
USERNAME="your username here"
SFTPHOST="your sftp host"
SFTPPORT=22 # or other port, if non-standard
# Create SSH key-pair for SFTP access
# (creates pair with no passphrase)
ssh-keygen -b 2048 -t rsa -C "$SFTPHOST" -N "" -f ~/.ssh/id_rsa.sftp
# Create authorized_keys file for upload
ssh-keygen -e -f ~/.ssh/id_rsa.sftp.pub -m RFC4716 > ~/.ssh/authorized_keys.sftp
chmod 600 ~/.ssh/authorized_keys.sftp
# Upload authorized_keys file to sftp
# (this will prompt for a password)
scp -P $SFTPPORT ~/.ssh/authorized_keys.sftp $USERNAME@$SFTPHOST:.ssh/authorized_keys
# Verify key-auth is working
# (should log in without password prompt)
sftp -o IdentityFile=~/.ssh/id_rsa.sftp -o Port=$SFTPPORT $USERNAME@$SFTPHOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment