I am trying to write a bash script that will allow me to login using ssh connection. The condition is that the password is stored into a .txt file.
I need to write a bash script that will automatically request a connection to
ssh USER@example.net -p 733
and automatically will use the passwords that are stored into a .txt file
I never wrote something in bash. Can someone help me. Thank you in advance for your time.
i suggest you to use password less authentication it will be more secure follow these steps :
then type
ssh -p 733 USER@example.net
you don't need to put any password again that's it password less authentication more secure than any script.You can't do it with plain
bash
script. You need to useexpect
command.Having said that it is really a very bad idea to have a password stored in a text file, here is how you can do it using
expect
:Still I suggest to follow @Wolph's advice to look into using a pair of keys when accessing a remote server using
ssh
.