Warning: Identity file /home/user/.ssh/id_rsa not accessible: No such file or directory


April 2019


658 time


I'm using Deployer for deploying my code to multiple servers. Today I got this error after starting a deployment:

[Deployer\Exception\RuntimeException (-1)]                                                        
The command "if hash command 2>/dev/null; then echo 'true'; fi" failed.                           
Exit Code: -1 (Unknown error)                                                                     
Host Name: staging                                                                                
Warning: Identity file /home/user/.ssh/id_rsa not accessible: No such file or directory.  
Permission denied (publickey).

First I thought it would probably has something to do with this server configuration since I moved the complete installation to another hosting provider. I tried to trigger a deployment to a server which I deployed to just fine in the past days but then got the same error. This quickly turned my suspicions from server to local.

Since I'm running PHP in docker (Deployer is written in PHP), I thought it might had something to do with my ssh-agent not being forwarded correctly from my host OS to docker. I verified this by using a fresh PHP installation directly from my OS (Ubuntu if that would help). Same warning kept popping up in the logs.

When logging in using the ssh command everything seems to be alright. I still have no clue what going on here. Any ideas?

PS: I also created an issue at Deployer's GIT repo: https://github.com/deployphp/deployer/issues/1507

1 answers


I have no experience with the library you are talking about, but the issue starts here:

Warning: Identity file /home/user/.ssh/id_rsa not accessible: No such file or directory.  

So let's focus on that. Potential things I can think of:

  1. Is the username really user? It says that the file lives at: /home/user. Verifying that that really is the correct path. For instance, just ls the file. If it doesn't exist, you will get an error:

    $ ls /home/user/.ssh/id_rsa

That will throw a No such file or directory if it doesn't exist.

  1. If 1. is not the issue, then most likely this is a user issue where the permissions are wrong for the user in the Docker container. If this is the issue, then INSIDE the Docker container, change the permissions on id_rsa before you need to do it:

    $ chmod 600 /home/user/.ssh/id_rsa
    Now do stuff with the key... 

A lot of SSH agents won't work unless the key is only read-write accessible by the user who is trying to run the ssh agent. In this case, that is the user inside of the Docker container.