Jenkins copy files between 2 Server - linux

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?

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

copy/move files on remote server linux

I log into server_a and run .sh file, which has the following script:
scp user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
to copy files from my_folder to my_new_folder at server_b. It doesn't throw an error, but no files are copied.
Notes:
server_b is accessed by the pre-set rsa_keys.
server_a: unix
server_b: ubuntu
can SCP files from/to these servers without any issues
The end goal is to move or copy/remove files.
There are two possibilities:
Connect from server_a to server_b and do local copy:
ssh user#server_b "cp /my_folder/my_file.xml /my_new_folder/"
Do copy over the server_a. Your method would require the server_b to be able to authenticate to itself, which is probably not the case:
scp -3 user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
Also note that your code copies only one file and not files as you write in the title.
If you are logged on to the server, why are you authenticating again:
scp user#server_b:/my_folder/my_file.xml user#server_b:/my_new_folder/
You should be in the directory of file or simply use scp and use -v parameter to see the debug information.
Run as follows:
scp -v /my_folder/my_file.xml user#server_b:/my_new_folder/
It is not a directory nor it is recursive, so you do not need to -r parameter.

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

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.

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.

scp from Linux to Windows [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I am running a putty client on a Windows machine to connect successfully to a Linux box. Now I want to be able to copy a file from the Linux machine under the path /home/ubuntu/myfile to C:/Users/Anshul/Desktop on my local computer. The user at the Windows machine is anshul. I am giving the following command on putty but it is not working:
scp /home/ubuntu/myfile ip_address_of_windows_machine:C:/Users/Anshul/Desktop
I think the path for the Windows machine is wrong. Please help as I have banged my head on a large number of forums but none seem to give correct path for Windows server. Don't suggest alternate options like WinScp
This one worked for me.
scp /home/ubuntu/myfile username#IP_of_windows_machine:/C:/Users/Anshul/Desktop
Download pscp from Putty download page, then use it from Windows Command Line CMD as follows:
pscp username_linux_machine#ip_of_linux_machine:/home/ubuntu/myfile.ext C:\Users\Name\Downloads
Copying starts once you enter the password for the Linux machine.
Try this, it really works.
$ scp username#from_host_ip:/home/ubuntu/myfile /cygdrive/c/Users/Anshul/Desktop
And for copying all files
$ scp -r username#from_host_ip:/home/ubuntu/ *. * /cygdrive/c/Users/Anshul/Desktop
Access from Windows by Git Bash console (also works for CMD and PowerShell):
scp user#ip:/dir1/dir2/file "D:\dir1\dir2"
You could use something like the following
scp -r linux_username#linux_address:path/to/file path/to/local/directory
This will copy file to the specified local directory on the system you are currently working on.
The -r flag tells scp to recursively copy if the remote file is a directory.
Windows doesn't support SSH/SCP/SFTP natively. Are you running an SSH server application on that Windows server? If so, one of the configuration options is probably where the root is, and you would specify paths relative to that root. In any case, check the documentation for the SSH server application you are running in Windows.
Alternatively, use smbclient to push the file to a Windows share.
For all, who has installed GiT completly with "Git Bash": You can just write:
scp login#ip_addres:/location/to/folders/file.tar .
(with space and DOT at the end to copy to current location). Than just add certificate (y), write password and that's all.
Your code isn't working because c:/ or d:/ is totally wrong for linux just use /mnt/c or/mnt/c
From your local windows10-ubuntu bash use this command:
for download:
(from your remote server folder to d:/ubuntu) :
scp username#ipaddress:/folder/file.txt /mnt/d/ubuntu
Then type your remote server password if there is need.
for upload:
(from d:/ubuntu to remote server ) :
scp /mnt/d/ubuntu/file.txt username#ipaddress:/folder/file.txt
Then type your remote server password if there is need.
note: I tested and it worked.
I had to use pscp like above Hesham's post once I downloaded and installed putty. I did it to Windows from Linux on Windows so I entered the following:
c:\ssl>pscp username#linuxserver:keenan/ssl/* .
This will copy everything in the keenan/ssl folder to the local folder (.) you performed this command from (c:\ssl). The keenan/ssl will specify the home folder of the username user, for example the full path would be /home/username/keenan/ssl. You can specify a different folder using a forward slash (/), such as
c:\ssl>pscp username#linuxserver:/home/username/keenan/ssl/* .
So you can specify any folder at the root of Linux using :/.
To send a file from windows to linux system
scp path-to-file user#ipaddress:/path-to-destination
Example:
scp C:/Users/adarsh/Desktop/Document.txt root#127.0.0.1:/tmp
keep in mind that there need to use forward slash(/) inplace of backward slash(\) in for the file in windows path else it will show an error
C:UsersadarshDesktopDocument.txt: No such file or directory
.
After executing scp command you will ask for password of root user in linux machine.
There you GO...
To send a file from linux to windows system
scp -r user#ipaddress:/path-to-file path-to-destination
Example:
scp -r root#127.0.0.1:/tmp/Document.txt C:/Users/adarsh/Desktop/
and provide your linux password.
only one you have to add in this command is -r.
Thanks.
Here is the solution to copy files from Linux to Windows using SCP without password by ssh:
Install sshpass in Linux machine to skip password prompt
Script
sshpass -p 'xxxxxxx' scp /home/user1/*.* testuser#x.x.x.x:/d/test/
Details:
sshpass -p 'password' scp /source_path/*.* windowsusername#windowsMachine_ip:/destination_drive/subfolder/
As #Hesham Eraqi suggested, it worked for me in this way (transfering from Ubuntu to Windows (I tried to add a comment in that answer but because of reputation, I couldn't)):
pscp -v -r -P 53670 user#xxx.xxx.xxx.xxx:/data/genetic_map/sample/P2_283/* \\Desktop-mojbd3n\d\cc_01-1940_data\
where:
-v: show verbose messages.
-r: copy directories recursively.
-P: connect to specified port.
53670: the port number to connect the Ubuntu server.
\\Desktop-mojbd3n\d\genetic_map_data\: I needed to transfer to an external HDD, thus I had to give permissions of sharing to this device.
Open bash window. Preferably git bash.
write
scp username#remote_ip:/directory_of_file/filename 'windows_location_you_want_to_store_the_file'
Example:
Suppose your username is jewel
your IP is 176.35.96.32
your remote file location is /usr/local/forme
your filename is logs.zip
and you want to store in your windows PC's D drive forme folder
then the command will be
scp jewel#176.35.96.32:/usr/local/forme/logs.zip 'D:/forme'
**Keep the local file directory inside single quote.
I know this is old but I was struggling with the same. I haven't found a way to change directories, but if you just want to work with the C drive, scp defaults to C. To scp from Ubuntu to Windows, I ended up having to use (notice the double back-slashes):
scp /local/file/path user#111.11.11.111:Users\\Anshul\\Desktop
Hope this helps someone.
Try this:
scp /home/ubuntu/myfile C:\users\Anshul\Desktop
If you want to copy paste files from Unix to Windows and Windows to Unix just use filezilla with port 22.

Resources