Permissions when trying to zip through SSH - bash

I don't how to get permissions to run zip command on the remote server. When I am on the server running this command: sudo -u the_user bash fixes this but when running this through ssh connection generates error: zip I/O error: Permission denied
This generates this error:
ssh "${SERVER}" \
"bash -s" <<'ENDSSH'>&1
zip -r "${DIR_NAME}.zip" $DIR_NAME
ENDSSH
If I add sudo -u the_user bash like so:
ssh "${SERVER}" \
"bash -s" <<'ENDSSH'>&1
sudo -u the_user bash
zip -r "${DIR_NAME}.zip" $DIR_NAME
ENDSSH
...I'm getting:
sudo: sorry, you must have a tty to run sudo

Related

Run a script on remote server with ssh password or key

I'm trying to run a script on a remote server with either password credentials or .pem key access and I'm getting errors no matter which solution I've found etc.
bash script content:
#!/bin/bash
sudo fdisk -l
ssh -T -i "~/.ssh/keys/key.pem" ubuntu#host "sudo bash <(wget -qO- http://host.com/do.sh)"
Error: bash: /dev/fd/63: No such file or director
ssh user#host.com 'echo "password" | sudo bash <(wget -qO- http://www.host.io/do.sh)'
Error: sudo: a password is required
ssh -t user#host.com "echo password | sudo fdisk -l"
Works but still gives me the password propmt
echo -t pass | ssh user#host "sudo bash <(wget -qO- http://host.com/do.sh)"
echo -tt pass | ssh user#host "sudo bash <(wget -qO- http://host.com/do.sh)"
Error: bash: /dev/fd/63: No such file or directory
// And I also get the password prompt
echo -tT pass | ssh user#host "sudo bash <(wget -qO- http://host.com/do.sh)"
Error: sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
// And I also get the password prompt
// This works but I still get the password propmt
ssh user#host 'echo "password" | sudo -S sudo fdisk -l'
These are different variations of the supposed solutions from other places.
What I'm trying to do:
Is to run a script from a URL on the remote server while echoing the password to the cmd so I don't get propmt to input the password manually.
To be able to do the same thing above with using the .pem key variant also
For an explanation for commands except the first one, You can't do stdin-redirect a password to ssh if ssh requires interactively. ssh only allows manual typing if you use a password.
Your first error said that bash can't read a file descriptor. So ssh via ~/.ssh/keys/key.pem works. To run the shell command on the fly,
ssh -T -i "~/.ssh/keys/key.pem" ubuntu#host "curl -fsSL http://host.com/do.sh | sudo bash"
Does your script really need to run with sudo??
If not, then try this:
ssh user#host "curl -s -o do.sh 'http://host.com/do.sh'; source do.sh"

sudo -S command does not recognize my password

I am trying to create a python script using sudo with echo, but the terminal always recognize my password as a command.
echo főzőedény|sudo -S su
echo "főzőedény"|sudo -S su
echo főzőedény|sudo -S -k su
[sudo] password for molnar: %
echo "főzőedény"|sudo -S -k su
[sudo] password for molnar:
Every time I got the same error message: zsh: command not found: főzőedény

Run bash script on remote server

I'm trying to run a bash script on the remote server that is already on the remote server. I'm using ssh pass to do it but I'm seeing errors
test.sh (resides on the remote server)
#!/usr/bin/env bash
echo "This is test"
adb start-server
sshpass command (I'm running this sshpass command from docker ubuntu image
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host "bash -s" < /Users/user/Documents/workspace/test.sh
I also tried
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host 'cd /Users/user/Documents/workspace/; sh test.sh'
I get this error message
bash: /Users/user/Documents/workspace/test.sh: No such file or directory
The examples you're showing are for a local script, and you said it's a remote script.
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host "bash /path/to/test.sh"
that ought to do it.
you can try to find your test.sh on the remote computer:
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host "find ~/ -name \"test.sh\""
Try with here-document:
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -T user#host <<EOF
bash /Users/user/Documents/workspace/test.sh
EOF
Include -T option for ssh command, as mentioned above, to disable pseudo-tty.
[AT REMOTE MATCHINE] Ensure that path of adb executable is included in PATH environment variable. Else, specify it with absolute path in the Shell script.

sshpass: Failed to run command: No such file or directory

I'm trying to run a remote sh from Jenkins to change a script to executable, but I take the following error:
[-manager_feature_kubernetes-YYLYXREUAV4NHLBACWJHV5YMQFOGHM4SS7G67ASIGYSZZGVS4VBQ] Running shell script
+ sshpass -p **** ssh'****#10.XX.XX.XXX chmod u + x /home/Script.sh '
sshpass: Failed to run command: No such file or directory
The logic of my script is:
        
sh "sshpass -p \" $ {passSSH} \ "ssh ${userSSH}#10.XX.XX.XXX \" chmod u + x /home/Script.sh \ ""
Can anyone help?
Have you tried this:
sshpass -p '$rootPassword' ssh -o 'StrictHostKeyChecking=no' $isRoot#$Host "chmod u+x /home/$USER/Script.sh"
Just write it here : my docker container did not have package lftp installed
a simple apt-get install lftp solved this issue.
Hope it will help ;)
In my case I was using docker container of alpine linux in which openssh was missing so sshpass failing. After installing openssh package it solved.
apk add openssh
(so just incase if some one faces same)
$rootPassword,$isRoot, $Host are Jenkins string parameter
sshpass -p ""$rootPassword"" ssh $isRoot#$Host id; echo $HOME;

mkdir: missing operand when doing sudo over ssh

I am trying to create directory with sudo user permission over SSH.
Here is the command i formed
some_command "ssh -t userA#host bash -c \"\'sudo -u userB bash -c \" mkdir -p /home/userB/dir_to_create \" \'\" "
here some_command is part of expect script.
I am getting this error :-
[sudo] password for userB:
mkdir: missing operand
Try `mkdir --help' for more information.
Connection to host closed.
If i run
sudo -u userB bash -c "mkdir /home/userB/dir_to_create"
it works.
ssh -t user#host "bash -c \"sudo -u otherUser bash -c 'mkdir -p /home/userB/dir_to_create'\""
should work
Based on comment from Mark Plotnick , i figured out the answer .
Here is the solution to it
spawn bash -c "ssh -t userA#host \"sudo -u userB bash -c 'mkdir -p /home/userB/perf_tools' \" "
Trick is that , single quote and double quote placements make all the magic happen in this script.

Resources