I have this bash file, which asks for IP, password, etc. for OpenSSH to a device.
Now, if i use ssh root@ip
, i have to enter the password. This is reall
The proper way to do this without storing passwords in plaintext on your machine is with ssh. First run:
ssh-keygen
This will generate a new SSH key in ~/.ssh/id_rsa.pub
. After that simply run:
ssh-copy-id user@my.server.com
If you're on OS X or another machine that does not have "ssh-copy-id" there are one-line alternatives such as this one:
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
Ultimately you just need to append the contents of ~/.ssh/id_rsa.pub
on your local machine to ~/.ssh/authorized_keys
on the remote server. How you do that is up to you, the above are just quick shortcuts to do that.
Even if I would use pem keys for this and this is an old topic, I also wanted to quote sshpass
Expect is the usual tool for automating interactive sessions.
Have you considered Paramiko? It's a Python-library for interacting with SSH.
You can use this script: https://github.com/aprey10/ssh-authorizer
It also allows to skip ssh keys passphrase request.
The proper way to go is to copy the keys as has been said here. To add something to the conversation, there are cases where sshpass
can be handy.
The question asks specifically about scripting in a system with SSH. If it is the development of an embedded system, it can be useful to combine sshpass
with command line options, as it reads on this post
sshpass -p raspberry ssh pi@192.168.0.145
this can be combined with
ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pi@192.168.0.145
to avoid confirmation questions that prevent scripting from happening.
Again, only use this in development systems where different machines share an IP and security is not important.
https://ownyourbits.com/2017/02/22/easy-passwordless-ssh-with-sshh/