How to copy files from a local machine to a server using the SSH file transfer protocol?

I have a Ubuntu 9.10 desktop machine that I use locally. I am setting up a server on a hosting provider. The server will run a very minimal version of the Ubuntu LTS server (only LAMP and an email server without a GUI).

I want to write a script (scheduled as a cron job) that will allow me to upload local files to the server. I want to use [SFTP] [1] for security reasons.

I'm new to shell scripts - but I think shell script is a way to do this (if I'm not mistaken).

Can someone provide me with initial pointers on how to start writing such a script in order to upload local files for FREE?

Ideally, I would like to compress the files before transferring (to save on the bandwidth)

[1]: http: // ssh file transfer protocol

+3
source share
2 answers

How to copy files from a local machine to a server using the SSH file transfer protocol?

Use scp.

I want to do this in a cron job.

The main problem with using scpcron in a job is this: where do you get your credentials? Putting your password in clear is not a good idea. It is best to have a process ssh-agentrunning on your computer. To find a suitable one ssh-agent, you can run this script:

#!/bin/sh

for i in $SSH_AUTH_SOCK /tmp/ssh*/agent*
do
  if [ -r "$i" -a -w "$i" ]; then
    case `SSH_AUTH_SOCK="$i" ssh-add -l` in
      *:*:*) echo "$i"; exit 0 ;;
    esac
  fi
done

exit 1

script , , SSH_AUTH_SOCK scp.

, ssh-agent ssh-add.

+4

"" "", , . , . , .

  • bourne. stackoverflow.
  • ssh-keygen, ssh-. scp cron, AFAIK. , , , , .
  • ssh ​​ .ssh/authorized_keys .
  • , , 'ssh target-machine' sans-password.

script, scp . :

#!/bin/sh
scp PATHNAME_OVER_HERE target-host:/PATHNAME_OVER_THERE

randoms, telnet. , , ssh, , , .

+6

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


All Articles