Escaping karate.fork Commands - karate

I am trying to run the following command in karate using karate.fork
ssh -o ProxyCommand="ssh -W %h:%p -i ~/.ssh/id_rsa root#myjumphost" -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o PasswordAuthentication=no root#finaldest echo test
I have broken this up into an array to pass to karate.fork like so:
[
ssh,
-o,
ProxyCommand="ssh -W %h:%p -i ~/.ssh/id_rsa root#myjumphost",
-i,
~/.ssh/id_rsa,
-o,
StrictHostKeyChecking=no,
-o,
PasswordAuthentication=no,
root#finaldest,
echo test
]
Then run the command like so:
* karate.fork(args) where args is the array mentioned above
The command works when I paste it into the terminal and run it manually, however when run with karate.fork I get
zsh:1: no such file or directory: ssh -W finaldest:22 -I ~/.ssh/id_rsa root#myjumphost
kex_exchange_identification: Connection closed by remote host
I have tried adding a few backslashes before the " in the ProxyCommand but no amount of back slashes fixes this issue. I think I am misunderstanding what karate.fork is doing to run the command, is there some internal parsing or manipulating of the given input? I was able to get this command to work when I used useShell: true however this option breaks other tests for me so I would really like to avoid it.

I had to remove the double quotes, seems like they didn't play well with karate.fork and the command still runs without them
[
ssh,
-o,
ProxyCommand=ssh -W %h:%p -i ~/.ssh/id_rsa root#myjumphost,
-i,
~/.ssh/id_rsa,
-o,
StrictHostKeyChecking=no,
-o,
PasswordAuthentication=no,
root#finaldest,
echo test
]

Related

Passing gitlab variables in sshpass script

Is there a way to add gitlab variables to the command ?
eg: variables: ARTIFACTORY_ADDRESS: "a.com"
script:
sshpass -p "password" ssh -o "StrictHostKeyChecking=no" user#SERVER 'echo $ARTIFACTORY_ADDRESS'
Currently its not taking the value from the variable and printing $ARTIFACTORY_ADDRESS in the console. I want the value to be printed in the console
Check first if using double-quotes would help enabling variable substitution:
sshpass -p "password" ssh -o "StrictHostKeyChecking=no" user#SERVER \
"echo $ARTIFACTORY_ADDRESS"
^^^ ^^^

How to escape ANSI format on remote SSH command?

I wanted to change the title of the window using the command as described here over SSH, however I kept get getting the error:
033]sh: Hello: command not found
Connection to host closed.
with the command:
ssh.exe user#host -t 'echo -en "\033];Hello World\007"'
No matter how I try to escape them, it seems to somehow return error. Tried:
ssh.exe user#host -t 'echo -en "\\033];Hello World\\007"'
ssh.exe user#host -t "echo -en \'\\033];Hello World\\007\'"
Any idea how to fix this?

"Force psuedo-tty allocation" doesn't translate to pssh

Supposedly, pssh's -x option passes along extra SSH command-line arguments. SSH's "-t" option should have taken care of the "Pseudo-terminal" error. Is there another pssh/ssh option that should be used?
# pssh -i -H ec2-user#xxx.xxx.xxx.xx1 -H ec2-user#xxx.xxx.xxx.xx2 -x "-t -i /tmp/key.pem" 'sudo hostname'
[1] 13:46:54 [FAILURE] ec2-user#xxx.xxx.xxx.xx1 Exited with error code 1
Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo
[2] 13:46:54 [FAILURE] ec2-user#xxx.xxx.xxx.xx1 Exited with error code 1
Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo
Without the "-t" and the "sudo", the command works fine, but I need to run some commands as sudo.
# pssh -i -H ec2-user#xxx.xxx.xxx.xx1 -H ec2-user#xxx.xxx.xxx.xx2 -x "-i /tmp/key.pem" 'hostname'
[1] 14:08:35 [SUCCESS] ec2-user#xxx.xxx.xxx.xx1
ip-10-0-0-140
[2] 14:08:35 [SUCCESS] ec2-user#xxx.xxx.xxx.xx2
ip-10-0-0-139
Try running pssh like this, so that the "-t" option is specified twice:
pssh -i -H ec2-user#... -x "-t -t -i /tmp/key.pem" 'sudo hostname'
^^^^^
The ssh man page says this about "-t" (emphasis added):
-t
Force pseudo-terminal allocation. This can be used to execute arbitrary
screen-based programs on a remote machine, which can be very
useful, e.g. when implementing menu services. Multiple -t options
force tty allocation, even if ssh has no local tty.
You are apparently running pssh in such a way that ssh has no local tty. So you have to arrange for ssh to be run with "-t" specified twice. This forces ssh to request a remote tty, despite not having a local tty.

Permission denied using ssh command in shell

I'm trying to execute this shell with command line
host="192.168.X.XXX"
user="USERNAME"
pass="MYPASS"
sshpass -p "$pass" scp -o StrictHostKeyChecking=no /home/MYPATH/File.import "$user#$host:/"home/MYPATH/
To copy a file from my local server in to remote server. The remote server is a copy of the remote server but when I try to execute this shell I have this error:
**PERMISSION DENIED, PLEASE TRY AGAIN**
I didn't understand why if I try to execute this command in command line is working.
USERNAME#MYSERVER:~$ sshpass -p 'MYPASS' scp -o StrictHostKeyChecking=no /home/MYPATH/File.import USERNAME#192.168.X.XXX:/home/MYPATH/
Somebody have a solution??
Please use a pipe or the -e option for the password anyway.
export SSHPASS=password
sshpass -e ssh user#remote
Your simple command with -e option:
export SSHPASS=password
sshpass -e scp -o StrictHostKeyChecking=no /home/MYPATH/File.import user#192.168.X.XXX:/home/MYPATH/
Please remove the wrong quotes from your command:
sshpass -p "$pass" scp -o StrictHostKeyChecking=no /home/MYPATH/File.import $user#$host:/home/MYPATH/
You should also be able to remove the quotes around $pass.
Please ensure that you have no special characters in your pass variable or escape them correctly (and no typos anywhere).
For simplicity use a ssh command instead of scp for testing
Use the -v or -vvv option for the scp command to check what scp is trying to do. Also check the secure log or auth.log on the remote server
You have to install "sshpass" command then use the below snippet
export SSHPASS=password
sshpass -e sftp user#hostname << !
cd sftp_path
put filename
bye
!
A gotchya that I encountered was escaping special characters in the password which wasn't necessary when entering it in interactive ssh mode.

StrictHostKeyChecking not Ignoring Fingerprint Validation

I'm Rsync-ing with the following command:
# rsync -arvce ssh /tmp/rsync/file.txt user#domain:/tmp/rsync/
This works fine, and I will have to do this for multiple places, so I want to implement the StrictHostKeyChecking option.
After reading other online examples I've added the option like this (3 examples):
# rsync -arvce ssh -o 'StrictHostKeychecking no' /tmp/rsync/file.txt user#domain:/tmp/rsync/
# rsync -arvce ssh -o 'StrictHostKeychecking=no' /tmp/rsync/file.txt user#domain:/tmp/rsync/
# rsync -arvce ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/rsync/file.txt user#domain:/tmp/rsync/
I still get prompted to validate the target server's key.
I understand the -o StrictHostKeychecking=no options let me choose whether to bypass that step each time I open a connection.
Am I doing it incorrectly?
here' some links I've read about this:
http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html
http://www.thegeekstuff.com/2010/04/how-to-fix-offending-key-in-sshknown_hosts-file/
http://www.cyberciti.biz/faq/linux-appleosx-howto-disable-ssh-host-key-checking/
I've resolved it.
Here's the correct (or mostly correct) way to add that option:
# rsync -e "ssh -o StrictHostKeyChecking=no" -arvc /tmp/rsync/file.txt user#domain:/tmp/rsync/
Appears there's a finicky way to apply the option, by adding double quotes and placing the ssh inside.