When connecting to the server via SSH via a script, there is a need to enter a password.


It turns out that when connecting to the server, it asks for a password:

ssh server@192.168.1.101 //Выполняю команду server@192.168.1.101's password: //Выводит консоль 

Addresses are constantly changing, passwords come from outside.


How to enter a password through a script?

  • four
    The motive of not being able to specify a password when connecting ssh is not to use passwords, use keys. (of course, you can use the password in the script if you wish, but I won’t tell you) - Vladimir Gamalyan
  • @VladimirGamalian, addresses are constantly changing, passwords come from outside. I need exactly vpisatt password. - user189127

2 answers 2

How to enter a password through a script?

for example, use the sshpass program (in popular distributions of the operating system gnu / linux is included in the package of the same name):

 $ sshpass -p 'пароль' ssh пользователь@сервер 

addresses are constantly changing

in this case, you will need to disable the known hosts check by adding the -q -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' options to the ssh program call:

 $ sshpass -p 'пароль' ssh -q -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' пользователь@сервер 

    It is better to set up a key system. This system allows you to not enter a password every time.

    But you can use the automation tool expect

    • Addresses are constantly changing, passwords come from outside. I need exactly vpisatt password. - user189127