I can connect to a server via SSH using the -i option to specify the private key:
ssh -i ~/.ssh/id_dsa user@hostname
I am creating a script that takes the id_dsa
text from the database but I am not sure how I can give that string to SSH. I would need something like:
ssh --option $STRING user@hostname
Where $STRING
contains the value of id_dsa
. I need to know the --option
if there is one.
To specify a private key file in SSH from the command line, you can simply use -i option in the ssh command. However, things get complicated when you have multiple private keys. In that case, you can declare which private key to use for each SSH server, in your SSH configuration file which is found at ~/. ssh/config .
ssh between systems is fine so long as it's limited to just files like authorized_keys , config , and known_hosts . If you want two hosts to be able to access each other, each host needs its own private SSH key, which must then be added to the other host's authorized_keys file.
Try the following:
echo $KEY | ssh -i /dev/stdin username@host command
The key doesn't appear from a PS statement, but because stdin is redirected it's only useful for single commands or tunnels.
There is no such switch - as it would leak sensitive information. If there were, anyone could get your private key by doing a simple ps
command.
EDIT: (because of theg added details in comment)
You really should store the key in to a temporary file. Make sure you set the permissions correctly before writing to the file, if you do not use command like mktemp
to create the temporary file.
Make sure you run the broker (or agent in case of OpenSSH) process and load the key using <whatever command you use to fetch it form the database> | ssh-add -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With