How to provide credentials for command line transfers

Description

When making transfers via the command line with ascp, there are a number of ways you can provide credentials for the transfer user of the server you’re connecting to. You can provide the transfer user’s password by typing it in when prompted, you can set the password as an environment variable, or you can set an SSH key for the user. When automating transfers such as with a script, the recommended method is using an SSH key as it is most secure. Instructions for all of these methods are below.

Manually entering the transfer user password

By default, you need to type in the transfer user’s password each time you make a transfer.

For example, to transfer file important-doc.txt to the document root of the user janedoe at example.com, you might use the following command and see the resulting password prompt:

ascp /path/to/important-doc.txt janedoe@example.com:/
Password:

After the password is authenticated, the transfer completes.

Setting an environment variable

You can also save the transfer user’s password in an environment variable if you prefer not to type it out each time, or if you are making transfers through a script.

The environment variable to set is ASPERA_SCP_PASS. You can set this environment variable using the following command, where transfer-user-pw is the password of the transfer user:

Linux and Mac OS X
export ASPERA_SCP_PASS=transfer-user-pw

Windows
set ASPERA_SCP_PASS=transfer-user-pw

Setting an SSH key

If you would prefer not to have to deal with the transfer user password at all, you can also set an SSH key for the user. This would only require you to include the location of your private key file in the ascp command in order to connect to the transfer user. Use the following instructions for setting an SSH key.

1. Create an .ssh folder in your home directory. You can do this with the following command:

Linux
mkdir /home/username/.ssh

Mac OS X
mkdir /Users/username/.ssh

Windows

md C:\Users\username\.ssh

2. Generate an SSH key-pair.

Run the following command in your .ssh folder:

ssh-keygen -t rsa

Press ENTER to use the default name id_rsa. You can choose to enter a passphrase, but since you are likely using SSH keys to avoid providing passwords, you can press ENTER twice to leave this blank.

3. Provide the public key file (id_rsa.pub, for example) to the administrator of the server you want to connect to. They will themselves create a .ssh folder in the transfer user’s home directory and add the public key to the end of the authorized_keys file.

4. You are now ready to make transfers with your SSH key. Your ascp command will need to include the -i flag followed by the location of the private key file you generated:

ascp -i path/to/home_dir/.ssh/id_rsa yourfile.txt transfer-user@host.com:/
Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk