Debugging file transfer using pscp executed from PowerShell - linux

I am trying to use PowerShell to send a file from a Windows 10 dev box to a CentOS 7 server across a local area network.
When I run the following command from PowerShell in the Windows 10 dev box, Putty opens, but then closes before asking for password. And then the test file (index.html) is not present in the intended destination folder on the CentOS 7 server.
Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw password C:\projects\temp\junk\index.html some_user_name#192.168.1.5:/home/some_user_name/")
How can I diagnose what problem is causing this command to fail? And what specific steps need to be taken in order for the file to be successfully transferred from the devbox to the server?
I have double checked the obvious things, like the file paths, the user name, and the IP.
The above command is derived from this suggestion by #GrahamGold.

In general, there's nothing wrong with your command. It should work (if all arguments are correct).
To diagnose the problem, first test the command on Windows command-line (cmd.exe):
"C:\Program Files (x86)\PuTTY\pscp.exe" -scp -pw password C:\projects\temp\junk\index.html some_user_name#192.168.1.5:/home/some_user_name/
This way, the output is preserved and you will see, what went wrong (if anything).
The next step is to do the same in PowerShell script using call operator & (though the result should be the same):
& "C:\Program Files (x86)\PuTTY\pscp.exe" -scp -pw password C:\projects\temp\junk\index.html some_user_name#192.168.1.5:/home/some_user_name/
If that works, it's time to replace & with the Start-Process cmdlet, if you really want that. But in general, I do not see a point of that, unless you want to run the transfer asynchronously.
Though if you want to make you command portable, you need to add -hostkey switch.
See my answer to Using echo y as an automated response to a pcp hostkey prompt.

Related

ssh No such file or directory

I had to wipe out my Windows OS. I went to check if I had ab ssh still and there was none so I created one.
Went through the proper steps and even got the agent ID.
Now when I try and find the id/rsa/pub using bash it tells me no file or directory.
But I can find that ssh file using my file explorer.
Trying to get ssh keys to reload up to my GitHub and Heroku.
After searching stackoverflow I did find an article saying to run the command env|grep HOME and make sure HOMEDRIVE=C: was set to HOMEDRIVE=C:Users/Samson/ but mine is not.
If that is the correct fix how do i set HOMEDRIVE=C: = to Users/Samson/
I am on a Windows Machine
If that isn't the correct fix, I'm open to suggestions. I am extrememly green to this.
Problem
There are two problems in the attempt to display the ssh public key, shown in the screenshot:
No command is used, the file path is entered directly. The command cat may be used for this purpose.
The file path is incorrect: id_rsa/pub instead of id_rsa.pub.
Solution
In order to view the public key file content, try the following command in bash:
cat ~/.ssh/id_rsa.pub
Otherwise, you may simply open the file from windows explorer, using a text editor (e.g. notepad).
You have to generate key first
Use this command to generate key
ssh-keygen -t rsa -b 4096 -C "youremail#example.com"
Enter the above email which you have in you github.
And now press enter and then you key will generate, and you will be able to acquire you ssh key
This command --
ssh-keygen -t rsa -b 4096 -C "youremail#example.com"
I am on a Windows Machine
Its okay to be on a Windows machine, but you should run these commands from a Git Bash window and not a windows command prompt or an anaconda command prompt. That maybe your real problem.

Linux shell to windows batch file

I have a Windows dedicated server and I installed Multicraft to run Minecraft servers, and I wanted to add a accept EULA button, since I did not know much about bat files, so I found a sh file online and I did not want to use Cygwin because I don't know how to install it and make it run properly.
I want to change this to a .bat file:
#!/bin/sh echo 'eula=true' > "$SERVER_DIR/eula.txt"
it basically finds the line eula=false in eula.txt and changes it to true from what i understand
I would guess that this is what you're looking for:
echo eula=true>>%SERVER_DIR%\eula.txt
Given the double greater-than symbol it should append the line to the indicated file. Note that we're using a backslash here. You might want to look at the contents of that SERVER_DIR environment variable to see if it will work on a Windows-based computer.
If you want to mirror the behavior in the UNIX script then use a single greater-than symbol to overwrite the file content.

How to pass encrypted password for execution of a script from Command Task to call pmrep

Scenario
I am working on a code to execute pmrep command. I cannot execute this from Unix box as the Code pages are different ( Unix server where I am executing the pmrep command and where the Power centre is installed), and I dont have any other option to exceute it from the Unix Box, because we dont have sudo login and we are connecting from citrix and Informatica is not installed locally.
So we have come up with an option of putting the pmrep commands in .sh script and passing username, password,environment and path variables from an env file. Then executing the above script from a command task in a workflow.
I am able to execute all the pmrep commands (connect, deploy DG etc) using the above process.
Now comes the problem.
I am saving my username and password in the .env file. I would like to remove this.
For pmrep connect command,
I am passing -x $password, I would like to pass the Encrypted password in place of original password.
I have used pmpasswd utility to get encrypted password and stored it in a variable (encrypted_password)
used that variable in place of orginal. -x $encrytped_password
used that variable with -X $encrypted_password.
where -x is used with general password and -X is used with Environmental Password
Both the methods were unsuccessful. with the first one its saying invalid password and with the second one its saying
"The environment variable xteyeZk9BYn91bb4Om7xKg== is undefined."
Please help me with the solution on this. Any help is really appreciated. Please let me know if you need more inputs.
Informatica(r) PMREP, version [9.1.0 HotFix6], build [496.0111], LINUX 64-bit
Rakesh
It should be -X encrypted_password without the $.

Replicating SCP command in Shell script in linux?

Hi I have been given a task of copying files from a given server to local machine. Even I can do it manually using the command line but I need to write a script to automate it. I dont have any clue how to do it using shell, how to give the password which we would have done manually. I went through other posts but did not get the precise answer.
Are there better ways than using SCP command?
Thanks in advance
The preferred + more secure way to do this is to set up ssh key pairs
That being said, if there's a specific need to supply passwords as part of your shell script, you can use pscp, which is part of putty-tools:
If you are on ubuntu, you can install it by:
sudo apt-get install putty-tools
(Or use equivalent package managers depending on your system)
Here's an example script of how to use pscp:
#!/bin/bash
password=hello_world
login=root
IP=127.0.0.1
src_dir=/var/log
src_file_name=abc.txt
dest_folder=/home/username/temp/
pscp -scp -pw $password $login#$IP:$src_dir/$src_file_name $dest_folder
This copies /var/log/abc.txt from the specified remote server to your local /home/username/temp/

to transfer files in linux fedora 12 by giving password at command prompt

I am fully aware that this question has been asked many times but I cant able to find any solution which satisy my requirement.
Task -> I need to transfer files from machine A to machineB and remotely execute scripts on Machine B. Due to my limitation I cant able to use keygen, expect utility or any other utility which requires to install packages. To Transfer the file I need to give password and I want to give password in Url. as this will run inside bash script and requires no user interference .
My investigation- I thought of using scp but realise, its not possible to give password at command prompt. So i wondering , if there is any other alternative from rsync .
below is the small attempt
#!/bin/bash
PATH=/usr/bin:/usr/sbin:/bin:/sbin
USER="bob"
RSYNC_PASSWORD="blue"
MACHINE_B="192.168.200.2"
if ping -c 1 -W 1 $MACHINE_B
then
echo "There is machine b as well"
echo " cheking to transfer file to machine b"
rsync lol.sh 192.168.200.2:/home/bob/
fi
Thanks and regards,
Sam
I have tried various option mentioned above ,, but unfortunately none of them works in my case. But I would like to thanks everyone for helping me and surely I have learned few new things specially rsync.
In my case, I have to rely on ssh keys to make it work.
From the rsync man page:
Some modules on the remote daemon may require authentication. If so, you will receive a password prompt when you connect. You can avoid the password
prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be useful
when scripting rsync.

Resources