Skip to content

Instantly share code, notes, and snippets.

@sephraim
Created April 12, 2023 15:05
Show Gist options
  • Save sephraim/627c42e4ad6bef7b5e8250803f86ab02 to your computer and use it in GitHub Desktop.
Save sephraim/627c42e4ad6bef7b5e8250803f86ab02 to your computer and use it in GitHub Desktop.
[sftp command line tool] using public key authentication

SFTP via the command line

Command

Use the following command to connect to an SFTP dropbox using public key authentication. Common locations for private key files include ~/.ssh/id_rsa and ~/.ssh/id_ed25519.

sftp -o PreferredAuthentications=publickey -o PubkeyAuthentication=yes -o PasswordAuthentication=no -o HostKeyAlgorithms=+ssh-rsa -i /path/to/private/key -P 19321 [email protected]

In the command above, we're using the sftp command with various options:

-o PreferredAuthentications=publickey: Specifies that the preferred authentication method is public key.
-o PubkeyAuthentication=yes: Enables public key authentication.
-o PasswordAuthentication=no: Disables password authentication.
-i /path/to/private/key: Specifies the path to your private key file, e.g. `~/.ssh/id_rsa` or `~/.ssh/id_ed25519`
-P 19321: Specifies the custom port number (in this example, 19321) to be used for the SFTP connection. Replace it with the actual port number used by your SFTP server.
[email protected]: Specifies the username and hostname or IP address of your SFTP server.

Settings

The following settings have not been tested.

# File: ~/.ssh/config

.
.
.
Host *.google.com
  HostName partnerupload.google.com
  Port 19321
  User myusername
  HostkeyAlgorithms +ssh-rsa
  IdentityFile ~/.ssh/id_rsa
  PubkeyAuthentication yes
  PasswordAuthentication no
  PreferredAuthentications publickey
  .
  .
  .

publickey should go before password.

# File: /private/etc/ssh/ssh_config

.
.
.
Host *
    PreferredAuthentications publickey,password,keyboard-interactive,hostbased,gssapi-with-mi
    .
    .
    .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment