Need to Transfer Files from One Linux Machine to Other Linux Machine via SFTP - linux

I have created a very small script below which i want help me to move files from one server to other server periodically via cronjob.
#!/bin/sh
HOST='1.1.1.1'
FILE='EndpointUsage*.*'
PASS='password#'
sftp kingadmin#$HOST
password $PASS <<END_SCRIPT
binary
lcd /var/tmp/
mput $FILE
quit
END_SCRIPT
Problem i am facing.
1) I need this script to give the password automatically, i do not want to give password manually whenever this script run. Currently when i ran the commands its asking for password as below.
LA:/var/tmp # ./portmove.sh
kingadmin#1.1.1.1's password:
2) I want to send the files to particular directory on remote server. Can you please help how to put the locations in the script so that my script can send the files to particular directory let say in every 10 minutes(which i can configure in cronjob)
Thanks you in advance.

Instead of using a password, consider using a public/private key pair.
You can then specify the key file instead of a password.

Related

Linux automatically transfers files through scp without a password

I now want to know how to execute an instll.sh file, and then transfer the file to another vm regularly through scp without entering a password
Here I define the party that transmits the file as vmA, and the party that receives the file as vmB
I can only do it after executing instll.sh, Iinstall.sh will create ssh key in vmA, and then transfer id_rsa.pub to the authorized_key file of vmB, but when I execute install.sh, he will execute the scp command If the error Host key verification failed. lost connection appears, I have to manually execute the scp command once, and then it will start to automatically execute the transmission work (I use crontab to automatically execute scp)
Explain what install.sh does
Copy some files to their respective directories, such as the files I want to transfer and cronatb..
Restart the crontab service
Please ignore it
Please ignore it
Automatically generate ssh key
Transfer the ssh key to the authorized_keys file of vmB
Execute the scp command once so that the connections on both sides can be successfully connected
When executing point 7, I will be asked to enter a password
Because this install.sh will be on different vm later, such as vmA, vmC, vmD, vmE, and they all need to transfer the data to vmB, I would like to ask if there is a way to execute the install.sh, just It will start to help me execute the work of spc without entering a password, and it can work normally

Make Vim keep the password while editing multiple files remotely

Consider you have a workstation, connect this to a remote server and edit some files in it like
workstation $ ssh sarah#192.0.0.100 # Log into the remote server
Password: MyPassw0rd!
server $ ls /home/sarah/recipes/ # Files you want to edit
applePie.txt bananaCake.txt
server $ vi /home/sarah/recipes/ # Open this directory and edit the files in it
...
:x
server $ logout # Log out and come back to the workstation
Now you want to use Vim/Neovim on your own workstation.
workstation $ vim scp://sarah#192.0.0.100://home/sarah/recipes/
sarah#192.0.0.100's password: MyPassw0rd!
The problem is every time you open files in this server you have to type the same password again. Is there any way to keep this SSH session alive while Vim/Neovim is editing files in the same remote server?
Netrw, which is the tool that handles loading and saving remote files, only prompts for passwords for FTP accounts. The prompt you're seeing is actually from scp, which, as part of OpenSSH, will only prompt for passwords from a TTY.
Because you're entering your password directly into scp and the scp process that's invoked doesn't live more than ephemerally, there's no way to cache your password. Even if Netrw did prompt for your password, scp doesn't provide a way to read passwords noninteractively, so Netrw couldn't cache it and pass it on.
You'll need to use SSH keys if you don't want to enter a password every time. To ease the setup burden, you can use ssh-copy-id to copy your keys just one time to the remote system, and then use Vim as normal without a password prompt.

Jenkins copy files between 2 Server

Is it possible to copy an .war file from one server to another server. I know there is the command scp but it doesn't support password & username. So there is like the command sshpass but I heard about some security problems with this command.
My question now: is there a way to pass an password trough the scp command without something like sshpass?

Simple shell/bash based sftp script to upload a file to root directory of destination server

I need to upload a file from source unix server to destination unix server (supports sftp). i'm using simple script below:-
cd /usr/bin
sftp userid#destination_server <<EOF
put myfile /
EOF
I get host key verification failed, Couldn't read packet: Connection reset by peer
I know this must have got something to do with correct public ssh key of my source being not set under destination server. But otherwise , is my script correct. Or do you suggest any other script based on my simple requirement stated above. Please note this doesn't need any password, just user name is sufficient and remote directory is just the root directory, hence using /.
Simply use a SFTP batch file:
sftp -b batchfile.sftp userid#destination_server
with batchfile.sftp containing exactly one line (or whatever more commands you should need)
put myfile /

Copy /etc/yum.repos.d/* to same directory on all computer without repetetively typing root password

I want to normalise the yum.repo files for all computers on our small network i.e
sudo scp /etc/yum.repos.d/* $HOSTNAME:/etc/yum.repos.d/
I can loop through all hostnames easily enough and execute the command to copy, however I am prompted for the root password on each occasion which is becoming tiresome. How can I script this with bash or perl so that I only need to type the root command in once?
Implement password-less authentication with ssh keys, as described here, for instance. This will allow to run scripts without password prompts using ssh key file in your home folder.

Resources