SSH Automation without Public Key Authentication or Waiting (1)

Is there a way to pass the ssh password automatically. I would like to automatically ssh to the server without using public key authentication or expect scripts, since getting ssh to read the password from stdin or file.

The reason for this is that I would like to backup my files on the server using rsync / ssh, which run as a cron job. This server mounts my home directory after it authenticates me, so using public key authentication does not work, since ~ / .ssh is not available until the login is successful. expect (1) is out of the question because I would like to run it as a cron job, and since cron jobs do not work under the terminal, the expect / ssh combination just doesn't work. I do not have root access to this server, and it would be difficult to get administrators to make any changes to the way everything works there.

+3
source share
7 answers

sshpass.

, password.txt :

sshpass -fpassword.txt ssh username@hostname

( )

+2

, cron, cron , expect/ssh

cron, , , , pexpect, Python. , , pscpect scp/ssh script cron, scp Python script, cron.

:

#!/usr/bin/python

import pexpect

FILE="/path/to/file"
REMOTE_FILE=""
USER="user"
HOST="example.com"
PASS="mypass"
COMMAND="scp -oPubKeyAuthentication=no %s %s@%s:%s" % (FILE, USER, HOST, REMOTE_FILE)

child = pexpect.spawn(COMMAND)
child.expect('password:')
child.sendline(PASS)
child.expect(pexpect.EOF)
print child.before
+6

SSH " " . ( , )

, SSH-SRP. , ssh.

, SSH " " .

0

, . , authorized_keys. google, .

-1
source

Do not use pending, pexpect or the like. to submit a password. If you do, your password should be somewhere in clear text, which in fact can be less secure than using a pair of public and private keys without a password. And it works more!

Read this page from β€œSSH: The Ultimate Guide” to discuss your options: http://www.snailbook.com/faq/no-passphrase.auto.html

-1
source

Source: https://habr.com/ru/post/1699255/


All Articles