Carry Private SSH RSA / DSA Key For Connection Using Unix / Linux Shell Script

Carry Private SSH RSA / DSA Key For Connection Using Unix / Linux Shell Script

To carry a private SSH RSA or DSA key for connection using a Unix or Linux shell script, you can use the ssh-add command.

The ssh-add command allows you to add a private key to the ssh-agent, which is a background process that holds private keys and forwards them to ssh when necessary.

Here is an example of how you can use the ssh-add command in a shell script to carry a private SSH RSA key:

# Start the ssh-agent
eval "$(ssh-agent -s)"

# Add the private key to the ssh-agent
ssh-add ~/.ssh/id_rsa

# Connect to the remote server using the private key
ssh user@remote.server
Source:w‮ttual.ww‬uri.com

This script will start the ssh-agent process, add the private key located in ~/.ssh/id_rsa to the ssh-agent, and then connect to the remote server using the private key.

To carry a private SSH DSA key instead of an RSA key, you can simply specify the path to the DSA key instead of the RSA key:

# Start the ssh-agent
eval "$(ssh-agent -s)"

# Add the private key to the ssh-agent
ssh-add ~/.ssh/id_dsa

# Connect to the remote server using the private key
ssh user@remote.server

This will carry the private DSA key for connection instead of the RSA key.

Overall, the ssh-add command is a useful tool for carrying a private SSH RSA or DSA key for connection using a Unix or Linux shell script. It allows you to easily add a private key to the ssh-agent and use it to connect to a remote server.

Created Time:2017-10-27 14:56:36  Author:lautturi