Permission issue while executing an ssh task in azure pipeline - azure-devops

What I am trying to do is to run a few lines of shell script in a remote machine via an azure pipeline. I used the ssh Deployment Task to accomplish this. I have used the script path argument to point the .sh file that contains the script that should be ran. The ssh task was able to connect to the remote host, but the following permission error pops up.
Can someone tell me what's going wrong here. The .sh file that i am using was created in the Linux box itself and has got the permission level set to 777 before moving to the repo.
There is an another CopyFilesOverSSH#0 task in the pipeline in the same stage which works perfectly without any permission issues for the same user.
2021-12-31T12:41:42.1763039Z ##[section]Starting: SSH
2021-12-31T12:41:42.1894277Z ==============================================================================
2021-12-31T12:41:42.1894676Z Task : SSH
2021-12-31T12:41:42.1895010Z Description : Run shell commands or a script on a remote machine using SSH
2021-12-31T12:41:42.1895347Z Version : 0.189.0
2021-12-31T12:41:42.1895637Z Author : Microsoft Corporation
2021-12-31T12:41:42.1896023Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/ssh
2021-12-31T12:41:42.1896437Z ==============================================================================
2021-12-31T12:41:42.8200834Z Trying to establish an SSH connection to ***#80.xxx.xxx.xxx:22
2021-12-31T12:41:43.1333018Z Successfully connected.
2021-12-31T12:41:43.5698433Z ##[error]Failed to copy script to remote machine. Error: Error: put: Permission denied //checkFileAvailability.sh.
2021-12-31T12:41:43.6050230Z ##[section]Finishing: SSH

Firstly, if you want to copy files to the remote machine, then it's recommend to use Copy Files Over SSH task. This task allows you to connect to a remote machine using SSH and copy files matching a set of minimatch patterns from specified source folder to target folder on the remote machine. Supported protocols for file transfer are SFTP and SCP via SFTP.
For the SSH Deployment task. This task enables you to connect to a remote machine using SSH and run commands or a script.
According to your error message, the SSH is successfully connected, but failed to copy script to the remote machine. It appears that the service account doesn't have the permission to copy the specified file to the specific path on the remote machine. Please check your source file path permission settings. Please also try to using inline script instead of the Script File to check if it works.

I had the same issue when run SSH script task under a user which was not a root. So for inline script to run under different user, that user should have:
Read/Write/Execute access to root folder, as TFS put all commands into generated bash script file and copy it to target machine root folder (below is another command, which is executed on already copied script file)
tr -d '\015' <./sshscript_099d4e8c-44ac-482d-b1bf-84a52c7ab810> ./sshscript_099d4e8c-44ac-482d-b1bf-84a52c7ab810._unix
User should have home directory as TFS switch to it
So to fix this issue I have granted rwx permissions to everyone for the root folder
chmod 777 /
ls -ld /
drwxrwxrwx 20 root root 4096 Feb 10 14:54 /
And make sure that home folder for my user exists

Related

scp-Host key verification failed-AzureDevOps

I want to copy file from Ubuntu 16.04 azuredevops agent to remote linux host (also have azuredevops agent installed).
I copied public key to ~/.ssh/authorized_keys
From terminal, all works fine
scp myagent/_work/10/s/docker-compose.yml root#192.168.1.76:/opt
docker-compose.yml 100% 1036 1.0KB/s 00:00
I created step in pipeline to execute exactly same command
But now getting error
2020-07-08T08:54:43.5359334Z [command]/bin/bash --noprofile --norc /home/user/myagent/_work/_temp/3ce8bc1e-7842-4f97-bc35-884893882d3c.sh
2020-07-08T08:54:43.5442624Z Pseudo-terminal will not be allocated because stdin is not a terminal.
2020-07-08T08:54:43.6019929Z Host key verification failed.
2020-07-08T08:54:43.6074975Z
2020-07-08T08:54:43.6245687Z ##[error]Bash exited with code '255'
You can use Copy Files Over SSH task to copy files to remote server.
First you need to create a SSH service connection to connect with with the remote server.
Go to project settings--> Pipelines-->Service connections-->new service connection-->Select SSH.
Then add Copy Files Over SSH task in your pipeline to copy the files to the remote server.
If you want to run script in remote server, you can use SSH task.

Is possible use the deploy connection to move files or another actions?

I have my pipeline to publish my code in an own server and works good, but now i would like do more actions like move differents files o delete them using the deploy group, is possible?
I don't know if I'm wrong, but i don't want open the server using a new connection through SSH.
Thanks for all!
Is possible use the deploy connection to move files or another actions?
I suppose you are have the connection through SSH to deploy your code to your server.
To more actions like move different files o delete them, you can try to use the SSH task, select the SSH service connection you deployed:
Then delete/remove the file with shell command, like:
file="file_you_want_to_delete"
if [ -f $file ] ; then
rm $file
fi
Code from: shell script to remove a file if it already exist.
Alternatively, you can use the Remote delete task to move files, which you can just provide:
Enter Remote Computer IP address
Enter User name and password for remote machine
Hope this helps.

Execute remote PowerShell script from VSOnline fails - Access Denied

I am facing a very strange issue trying to run a Remote PowerShell script from the new build system of Visual Studio Online.
Context:
I have a Build server that I host on my own VM. I have also created a second VM where I want the PowerShell script to be run on.
When I run a build from the Build server, I want to create a task that run a PowerShell script on a remote machine. Sounds easy.
Both machines have everything configured to run the Remote PowerShell. (I think)
Problem:
If I manually run the script from the build server, the script is properly executed on my remote machine.
But, if I run the script by starting a new build, it doesn't work, I always get an error message
New-PSSession : [xxx.cloudapp.net] Connecting to remote server xxx.cloudapp.net failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
Have you faced this issue before with VSOnline?
This can happen if there isn't a trust relationship between the remote machine and the build machine. E.g. you could look at the hosts.equiv file on the remote machine and make sure it trusts the build machine.
If that doesn't help then more info might be needed, like how you're trying to sign in, what build agent account you're running as.
Guy

Installing agents on solaris remotely

In regard to Uptime.
I want to install the agents on solaris machine remotely through putty.
Now for that, I have established(logged in) a connection to that system successfully.
following this, my next step would be to "Using a file transfer method such as FTP, transfer the archive containing the Agent to the system on which you want to install it. You should copy the archive to a temporary directory on the system."
Now my problem is that i am unable to transfer the archive containing the agent, to the system on which i logged in through putty.
I have searched this command to transfer the files rcp machinename:source destination
here my machine name is:
\uptime-share.uptimesoftware.com\css\Releases\Agents\Solaris
source : uptimeagent-7.2.1-solaris-sparc
destination : 172.20.98.14/tmp
but after using this command i get the message connection refused.
Could someone help me to do this.
I used this command
rcp 172.20.32.11:/css/Releases/Agents/Solaris:uptimeagent-7.2.1-solaris-sparc 172.20.98.14/tmp

JasperReports Server Installation fails while executing initdb.exe of postgresql

JasperReports Server 5.6.0
I am able to successfully install JasperReports Server in unattended mode, when login to a specific machine as local Administrator. But I want to do the installation from a remote machine and am passing the same parameters as earlier(invoking the setup using CPAU for run as admin), but it fails while executing initdb.exe with the data folder creation.
I am getting the following error message as stated below.
"Executing initdb.exe -U postgres -E UTF8 -D C:/JASPER~1/JASPER~1.6/POSTGR~1/data
Script exit code: unknown signal
Script output:
Script stderr: child killed: unknown signal"
After googling and looking for a possible solution, I tried the following.
1) Created the data folder via cmd and provided full control permissions using cacls
2) Created the parent folder 'JasperServer' and provided inheritance permissions of OI, CI, Full Control.
But the issue appears to be the same. Though I am able to install JR Server with the same account by rdp in to the specific machine.
Can anyone help me out?
pls try this:
http://community.jaspersoft.com/wiki/bundled-installer-fails-error-running-initdbexe
Reason: You are using domain admin account.
Solution:
change to local admin user and restart install procedure,then it works:-)
By, Kosta