SCP from local server to remote


(Deepchandna) #1

Can anyone please send me a working example for SCP? I have error in my below code. PLease suggest in that as well.

[admin@fff06789 .ssh]$ st2 run core.local cmd='scp '/home/admin/.ssh/id_rsa' /opt/stackstorm/packs/xyz/actions/scripts/xyz_OS_uptime.sh hldc017.abc.xyz.com:/home/m57684'
id: 5b5d51f53648f875c6e892a6
status: failed
parameters:
  cmd: scp /home/admin/.ssh/id_rsa /opt/stackstorm/packs/xyz/actions/scripts/xyz_OS_uptime.sh hldc017.abc.xyz.com:/home/m57684
result:
  failed: true
  return_code: 1
  stderr: "Host key verification failed.
lost connection"
  stdout: ''
  succeeded: false
[admin@fff06789 .ssh]$

#2

Without a great deal more context, I can only speculate and offer hints as to how to fix whatever is going on.

Review the command line flags for the scp command. The command you are asking StackStorm to run is not properly formatted to do what you want to do.

You should be passing the -i flag to ssh before the private key:

ssh -i /home/admin/.ssh/id_rsa ... ...

that will tell the SSH command to use that private key (aka “identity file”) when connecting to the remote server.

Next verify that StackStorm is running the command as the user you expect. To find the user StackStorm is using to run the action, run the following:

st2 run core.local cmd='whoami'

Furthermore, you should specify what user the SSH client should connect to the remote server as. Do you want to connect as the StackStorm user you just found in the last command? Or do you want to connect as the admin user? Specify that on the command line:

ssh ... <user>@hldc017.abc.xyz.com:/home/m57684

Replace <user> with the username you wish to use for the remote server.

On top of that, make sure that you are not trying to overwrite the entire home directory of the m57684 - this could also be the cause of the error. To make sure the SSH client adds the file to the /home/m57684 directory, append the directory name with a /:

ssh ... <user>@hldc017.abc.xyz.com:/home/m57684/

(note the / at the end of the command)

If you follow all of these hints and it still doesn’t work, please post the complete error using Markdown formatting, as well as any more relevant context you can think of. It is impossible to accurately diagnose problems and very difficult to solve them with as little information as you have given so far.


(Deepchandna) #4
Private key permission is -rw------- 1 st2admin stkstrm 1671 Jul 24 21:32 id_rsa

(Deepchandna) #5

Issue resolved and data sent to bin


(Deepchandna) #6

Issue resolved and data sent to bin


#7

That error indicates that StackStorm cannot access the key file.

StackStorm does not run as the same user as you. You are logged into your local machine as st2admin, but StackStorm is running the same command as a different user.

You will need to make the SSH key file readable to the user that StackStorm is running as. The best way to do this is to find the user StackStorm is using, and add that user to the stkstrm user group.


(Deepchandna) #8

StackStorm is running the same with command with st2admin user only because i have configured it in “/etc/st2/st2.conf” file.

user = m40725
ssh_key_file = /home/st2admin/.ssh/id_rsa

Also, key is kept already in 

pwd /home/st2admin/.ssh ls -ltr id_rsa
-rw------- 1 st2admin stkstrm 1671 Jul 24 21:32 id_rsa
$


#9

What is the output of st2 run core.local cmd=whoami?


(Deepchandna) #11
I got it. Let me try.

(Deepchandna) #12

@blag, You suggestion and guidance worked. Thank you so much.


#13

You’re welcome. Good to hear you got it working!