Getting around the password prompts in SCP

You can publish your docs via SSH through a Terminal window or more likely, via a shell script that you simply execute as part of the publishing process. However, you will be prompted for your password with each file transfer unless you configure passwordless SSH. The basic process for setting up password less SSH is to create a key on your own machine that you also transfer to the remote machine. When you use the SCP command, the remote machine checks that you have the authorized key and allows access without a password prompt.

Get rid of password prompts

To remove the password prompts when connecting to servers via SSH:

On your local machine, go to your .ssh directory:

cd ~/.ssh

Note that any directory that starts with a dot, like .ssh, is hidden. You can view hidden folders by enabling them on your Mac. See this help topic. Additionally, when you look at the files in a directory, use ls -a instead of just ls to view the hidden files.

If you don’t have an .ssh directory, create one with mkdir .ssh.

Create a new key inside your .ssh directory:

ssh-keygen -t rsa

Press Enter. When prompted about “Enter file in which to save the key …”, press Enter again.

This will create a file called id_rsa.pub (the key) and id_rsa (your identification) in this .ssh folder.

When prompted for a passphrase for the key, just leave it empty and press Enter twice. You should see something like this:

Switch back into your terminal window that is connected to remoteserver.com, change directory to the .ssh directory, and rename the file from id_rsa.pub to authorized_keys (without any file extension):

mv id_rsa.pub authorized_keys

Change the file permissions to 700:

chmod 700 authorized_keys

Now you should be able to SSH onto remoteserver without any password prompts.

Open another terminal (which is not already SSH’d into remoteserver.com) and try the following:

ssh <your_username>@remoteserver.com

If successful, you shouldn’t be prompted for a password.

Now that you can connect without password prompts, you can use the scp scripts to transfer files to the server without password prompts. For example: