Change Kex Algorithm for pscp File Transfer from Powershell - windows

I'm using Powershell to write a sftp script using pscp from PuTTY to transfer files between windows machines. The issue is the Key Exchange algorithm options are not selectable from command line.
Command used:
D:\apps\PuTTY\pscp.exe -i $private_key_path ${from_path} ${username}#${host_name}:${target_path}
$private_key_path = absolute path to private key
$from_path = path to local file
$username = username for host server
$host_name = host server name/ip
$target_path = host server filepath to save local file to
The following error occurs:
Fatal: Disconnected: Server protocol violation: unexpected SSH2_MSG_UNIMPLEMENTED packet
By following the instructions on this page PuTTY SSH2_MSG_UNIMPLEMENTED Error, basically you change the key auth algorithm hierarchy so the correct one is selected. Then I saved this session in PuTTY.
You can load a saved PuTTY session and I used the following command to successfully run file transfers:
D:\apps\PuTTY\pscp.exe -load "SavedSession" $from_path $username#$host_name:$target_path
Now the question is: is there a way to do this without a saved PuTTY session? As in, is there a way to define the Key Exchange algorithm as part of the command?
It defaults to Diffie-Hellman group exchange, but I need it to be anything else.
The host name might change as well as this script being migrated to different servers so change management for the PuTTY sessions between environments will be an issue.

Related

Copy file to multiple hosts from a shared file server with password

I have about 20 Macs on my network that always need fonts installed.
I have a folder location where I ask them to put the fonts they need synced to every machine (as to save time i will install the font on every machine so that if they move machines, i don't need to do it again)
at the moment I am just manually rsyncing the fonts from this server location to all the machines one by one using
rsync -avrP /server/fonts/ /Library/Fonts/
this requires me to ssh into every machine
is there a way i can script this using a hosts.txt file with the ips? the password is the same for every machine and i'd rather not type it 20 times. Security isn't an issue.
something that allows me to call the script and point it at a font i.e.
./install-font font.ttf
I've looked into scp but I don't see any example of specifying a password anywhere in the script.
cscp.sh
#!/bin/bash
while read host; do
scp $1 ${host}:
done
project-prod-web1
project-prod-web2
project-prod-web3
Usage
Copy file to multiple hosts:
cscp.sh file < hosts
But this asks me to type a password every time and doesn't specify the target location on the host.
I don't see any example of specifying a password anywhere in the script.
Use ssh-copy-id command to install your public key to each of these hosts. After that ssh and scp will use public-private key authentication without requiring you to enter the password.

file transfer from remote server to sftp using shell script

I have a file in my remote server which needs to be transferred to sftp box.
I do have the password, port and username for sftp box.
Please share me a shell script programming to understand how this can be done.
you can go for passwordless authentication between remote server and sftp box via sharing the public key .
OR , you can use
scp filename sftpuser#sftphost:/$destination_Path

How to login ssh server without giving password using private/public key- imported-openssh-key

Currently Filezilla is being used to copy from remote sever. there is require manual operation requires to copy and complete other further task after copying file. SO i need to write shell script to copy and do further task. But i facing to login server using private/public key. I have one key file which is containing following content:
puTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
--<Public_key>
Private-Lines: 14
---<Private_key>--
Private-MAC: --<some text>--
Filiezilla is successfully connecting and working properly using key .
I have already spent many hours for googling, But could not get proper solution.
Please suggest me how do i login without password using that given key and copy file using shell script
You need to put the private key in a file by itself on the client machine, and then:
ssh -i /path/to/ssh/key USER#HOSTNAME
Here's a tutorial: https://support.rackspace.com/how-to/logging-in-with-an-ssh-private-key-on-linuxmac/
Finally I got the solution of my own question after doing research and visiting many website. PPK file contains:
puTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
--<Public_key>
Private-Lines: 14
---<Private_key>--
Private-MAC: --<some text>--
Actually we need to generate our own private key either with pass-phrase or without pass-phrase. Then we can login server using own private key.
Steps to generate private key in this url
https://kb.paessler.com/en/topic/32883-how-can-i-use-private-keys-for-my-ssh-sensors-with-prtg
After generating private key, we can do ssh login or stp using :
sftp -oIdentityFile=<generated_private_key> <user>#<ftp_server>:<remote_directory>
ssh -i <generated_private_key> <user>#<ftp_server>
we can use importance stp_command for automation task:
http://www.csee.umbc.edu/courses/104/fall05/ordonez/sftp_cmds.shtml
Now i can write shell script after login and listing file on Remote FTP server. if anything confusion. pls comment.

SCP file from ssh session to localhost

I have a headless file server on which I store and manage downloads and media, but occasionally I have to transfer small files back to my computer (Mac, using bash shell). The problem is that some files have more user-friendly names and commonly have spaces in them, and they are buried in the file directory hierarchy I have set up on my server.
When I'm using scp from my local machine, I don't have tab completion, so I have to manually type out the entire path and name with spaces escaped. When I ssh into the server first, the command:
scp /home/me/files/file\ name\ with\ spaces.png Me#localhost:/Users/Me/MyDirectory
fails with the error "Permission denied, please try again" even though I'm entering my local machine user password properly.
I've learned a little bit of sftp since I've been told that may be a better tool for file transfer. However, the utility seems outdated and I still don't have tab completion after establishing a connection to the server (on my Terminal when pressing Tab I just get a tab character).
My question is this: what can I do to allow tab completion while using scp from my Mac? Or am I using incorrect syntax for scp while in an ssh session, and is there something in that command I should fix? Or, is there a (better? newer?) tool other than sftp that would offer tab completion on a server?
Finally, if none of these problems have simple solutions, is there some package I could install (e.g. a completion package from Homebrew or the like) that would facilitate better tab-completion with any of these commands?
Looks to me like this is some incorrect scping.
This is the format of the command
scp ./localFile.txt remoteUser#remoteHost:/remoteFile.txt
You were so close, but you have localhost set where you should have your remoteHost.
localhost is the name that resolves to the machine that you are currently on - so in your workflow, you are sshing to a machine, and then trying to scp that file to the same machine you are already sshd into.
What you need to do, is figure out the IP address, or the physical host name of the computer that you are trying to connect to, and use that instead.
scp ./localFile.txt remoteUser#192.168.1.100:/remoteFile.txt
# where 192.168.1.100 would be the IP of your Mac
I am assuming the reason you were getting permission denied, was because you were using your the login credentials for you mac, but unknowingly trying to login again to your headless machine.

Shell Script to Copy file from one server to another

I have 2 solaris servers. I want to write a shell script which will copy a file from one server to the other.
scp /tmp/test/a.war tomcat#202.203.204.44:/tmp/
The above command when executed in PUTTY will ask me to enter a password for the destination. This is fine when using PUTTY.
How can iI enter the password while running the scp command through shell script?
Thanks in advance
You have to setup SSH private/public key.
Once generated place the public key line entry on the target server's and user's ~/.ssh/authorized_keys file.
Make sure the file on the source machine (for the user which will run the scp/ssh command) will have file permission (400) recommended.
https://unix.stackexchange.com/questions/182483/scp-without-password-prompt-using-different-username or
http://docs.oracle.com/cd/E19253-01/816-4557/sshuser-33/index.html or similar online help can help you.

Resources