The task is to run a small script:

ssh [email protected]<<'ENDSSH'
pm2 stop myapp
git pull origin master
npm install
npm run build
pm2 start myapp

Problem: at the git pull origin master stage, I get an error that I don’t have access rights.

Cloning into'issue'...
Permission denied(publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights.
and the repository exists.

If I execute this command myself, logging into the server via SSH - everything works! So why does not work when I run through the script? What key is he trying to use?(On the local machine and VPSke different keys for GitHub, but the account is the same)
  • Well, there everything is written to mine
    Permission denied(publickey)
    NOT the key to this server that you visit, it’s where it belongs.
    – Small-Time41 Nov 28 '17 at 09:12
  • Small-Time41, what’s the key to the server? On the local machine, the key to the Githab is also there.Thanks for the translation, otherwise I am a fool. – Hungry63 Nov 28 '17 at 19:13
  • Once again for those who did not understand the first time - on the local machine and the UPU have the keys to Gitkhaba. – Hungry63 Nov 28 '17 at 19:14
  • Hungry63, well, it is necessary to inform your computer, one way or another, he does not see them. – Small-Time41 Nov 29 '17 at 09:07
  • Small-Time41, a local computer sees a local file, what should it tell? – Hungry63 Nov 30 '17 at 17:02

1 Answers 1

The server key should be used, not the local machine.
Maybe you have different users used in the script and when manually logging in and, accordingly, different keys are taken?
  • On a local machine, a key that is registered on Github.Both keys are registered on Github - both local and in sevre – Hungry63 Nov 28 '17 at 19:12
  • The user is the same. – Hungry63 Nov 28 '17 at 19:12