angrychimp
1/24/2017 - 6:37 PM

Setting up SSH keys for key-auth with ProFTPd (w/ SFTP module)

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