I want to use SSH
inside a script, but this script is not going to be executed on my machine.
In my implementation there are two limitations.
- I can not work outside shell's standards,therefore i can not use
expect
because i do not know if it will be available on this machine. - I can not expect that this machine will have
public keys
for theSSH
.
What are the possible options-solutions ?
How can i provide ssh with the requested password with an automated and secure way without adding extra dependencies?
Will it be possible to provide the password inside the script?
Thank you all in advance :)
AFAIK there is no possibility beside from using keys or expect if you are using the command line version
ssh
. But there are library bindings for the most programming languages like C, python, php, ... . You could write a program in such a language. This way it would be possible to pass the password automatically. But note this is of course a security problem as the password will be stored in plain text in that programFirst of all: Don't put secrets in clear text unless you know why it is a safe thing to do (i.e. you have assessed what damage can be done by an attacker knowing the secret).
If you are ok with putting secrets in your script, you could ship an ssh key with it and execute in an
ssh-agent
shell:A benefit of using ssh keys is that you can easily use forced commands to limit what the keyholder can do on the server.
A more secure approach would be to let the script run
ssh-keygen -f ~/.ssh/my-script-key
to create a private key specific for this purpose, but then you would also need a routine for adding the public key to the server.Install sshpass, then launch the command:
For security reasons you must avoid providing password on a command line otherwise anyone running ps command can see your password. Better to use sshpass utility like this:
You might be interested in How to run the sftp command with a password from Bash script?