I am trying to executing a jar file
which is present in remote machine. When I execute below command from my local machine I get error:
ssh -i /root/.ssh/pem_file user@[host_ip]:/home/user/folder1/java -cp jar1.jar -a option1 -e user1@gmail.com -f TextFile.txt
/home/user/folder1/
is the location where jar file
is present on remote machine.The error I get is:
Unknown cipher type 'p'
I then looked up for this error and found out the with ssh
we may not need it. So, I removed -cp from it and executed this command:
ssh -i /root/.ssh/pem_file user@[host_ip]:/home/user/folder1/java jar1.jar -a option1 -e user1@gmail.com -f TextFile.txt
Now I get error as:
ssh: Could not resolve hostname [host name]:/home/user/folder1/java: nodename nor servname provided, or not known
How can I resolve this error?
The command should be passed to ssh
after hostname separated by space not colon, like this:
ssh -i /root/.ssh/pem_file user@[host_ip] /home/user/folder1/java -cp jar1.jar -a option1 -e user1@gmail.com -f TextFile.txt
If you have parts in the command that could be parsed by your local shell before sent to remote host (for example cd /tmp && ls
or cat /file | uniq > some.log
) it should be enclosed in single quotes:
ssh -i /root/.ssh/pem_file user@[host_ip] 'cd /home/user/folder1 && java -jar jar1.jar -a option1 -e user1@gmail.com -f TextFile.txt'
Is that a executable jar?
ssh -i /root/.ssh/pem_file user@[host_ip] 'java -jar jar1.jar -a option1 -e user1@gmail.com -f TextFile.txt'
Otherwise, follow -cp
with the main class:
ssh -i /root/.ssh/pem_file user@[host_ip] 'java -cp jar1.jar full.package.name.ClassName -a option1 -e user1@gmail.com -f TextFile.txt'