Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

The SSH@0 task cannot log in to the remote machine

ErrorFailed 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.

  • Applies to Azure Pipelines SSH@0, Ubuntu 24.04 target, OpenSSH 9.6
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.10
  2. 2Match what you see, then jump to its fix

    1. 1The manual ssh -v run ends with 'Permission denied (publickey)'The public key is not installed for that user on the remote machineFix
    2. 2The key works in your terminal, but the pipeline still fails to authenticateThe key type is not one the task supportsFix
    3. 3The server has PasswordAuthentication set to no, and the connection uses a passwordThe service connection has a password but the server expects keyboard-interactiveFix
    4. 4The manual login works but takes several seconds before it prompts or runsThe handshake is slower than the task allowsFix

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_key

2Fix

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_keys

3Verify

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

Did this fix it?

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.pub

2Fix

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 server

3Verify

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

Did this fix it?

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_config

2Fix

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: true

3Verify

Run the pipeline and check that the task prints the command output.

# pipeline log shows the output of: uptime

Confirmed by learn.microsoft.com

Did this fix it?

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 true

2Fix

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 completes

Confirmed by learn.microsoft.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.