The SSH@0 task cannot log in to the remote machine
Failed to connect to remote machine. Verify the SSH service connection details.Short answer
The SSH task logs in with the details stored in its SSH service connection, so the failure is almost always in that connection or on the server. Check that the private key and passphrase are filled in, the public key is installed for that user, the key type is RSA or DSA, and that password logins match the server.
Fix it fast
1Find out which cause you have
Try the same login by hand from any machine, with the same user and the same private key as the service connection. If it fails there too, the problem is the key or the server, not Azure Pipelines. The verbose output shows which methods the server offers.
ssh -v -i ./deploy_key deploy@203.0.113.102Match what you see, then jump to its fix
- 1
The manual ssh -v run ends with 'Permission denied (publickey)'The public key is not installed for that user on the remote machineFix - 2
The key works in your terminal, but the pipeline still fails to authenticateThe key type is not one the task supportsFix - 3
The server has PasswordAuthentication set to no, and the connection uses a passwordThe service connection has a password but the server expects keyboard-interactiveFix - 4
The manual login works but takes several seconds before it prompts or runsThe handshake is slower than the task allowsFix
- 1
What does the error look like?
Failed to connect to remote machine. Verify the SSH service connection details.All configured authentication methods failed
Cause 1 of 4
The public key is not installed for that user on the remote machine
1Check
The SSH task uses a key pair, and the public half has to be installed on the remote machine already. Look in the authorized_keys file of the user named in the service connection.
sudo cat /home/deploy/.ssh/authorized_keys
ssh-keygen -y -f ./deploy_key2Fix
Append the public key that matches the private key stored in the service connection, and keep the folder and file permissions strict.
sudo -u deploy mkdir -p /home/deploy/.ssh
echo "ssh-rsa AAAA...your-public-key..." | sudo -u deploy tee -a /home/deploy/.ssh/authorized_keys
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys3Verify
Run the manual login again; it should open a shell. Then re-run the pipeline.
ssh -i ./deploy_key deploy@203.0.113.10 'echo ok'Confirmed by learn.microsoft.com
Cause 2 of 4
The key type is not one the task supports
1Check
The task documentation lists RSA and DSA as the supported key pair algorithms. Print the type of the key you stored in the service connection.
ssh-keygen -l -f ./deploy_key.pub2Fix
Create an RSA key pair for the pipeline, install its public key on the server, and put the new private key (and its passphrase, if any) into the service connection.
ssh-keygen -t rsa -b 4096 -f ./pipeline_key
# then append ./pipeline_key.pub to /home/deploy/.ssh/authorized_keys on the server3Verify
Re-run the pipeline. The connection step should pass and your commands should run.
ssh -i ./pipeline_key deploy@203.0.113.10 'echo ok'Confirmed by learn.microsoft.com
Cause 3 of 4
The service connection has a password but the server expects keyboard-interactive
1Check
The task page says to turn on interactive-keyboard authentication when PasswordAuthentication is disabled on the target. It also says passwords are not supported for macOS or Windows targets, only for Linux.
sudo grep -i passwordauthentication /etc/ssh/sshd_config2Fix
Prefer a key. If you must use a password on a Linux target, set interactiveKeyboardAuthentication in the task.
- task: SSH@0
inputs:
sshEndpoint: 'my-ssh-connection'
runOptions: 'commands'
commands: 'uptime'
interactiveKeyboardAuthentication: true3Verify
Run the pipeline and check that the task prints the command output.
# pipeline log shows the output of: uptimeConfirmed by learn.microsoft.com
Cause 4 of 4
The handshake is slower than the task allows
1Check
readyTimeout is the number of milliseconds the task waits for the SSH handshake, and its default is 20000.
time ssh -i ./deploy_key deploy@203.0.113.10 true2Fix
If the manual login takes several seconds, raise the timeout in the task.
- task: SSH@0
inputs:
sshEndpoint: 'my-ssh-connection'
runOptions: 'commands'
commands: 'uptime'
readyTimeout: '60000'3Verify
Re-run the pipeline a few times; the connect step should pass each time.
# pipeline log: SSH task completesConfirmed by learn.microsoft.com
How do I stop it coming back?
- Make a dedicated deploy user and key pair for the pipeline, and note which server user owns the public key.
- Test every new service connection with a manual ssh -v run before wiring it into a pipeline.
- Use RSA keys for this task and keep the passphrase in the service connection, not in the YAML.
- Keep PasswordAuthentication off on the server and use keys only.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Azure App Service on Linux restarts the container and the site never starts
The container restarts again and again and the site returns an application error
App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time.
5 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix