Home > Back-end >  How do I set up my Linux server to connect to repository?
How do I set up my Linux server to connect to repository?

Time:07-02

I am a relatively inexperienced developer trying to take over the development of a website from the previous coders.

The code exists on a repository on Github and the website is hosted on a Linux server. I can log remotely into the server as a non-root user and run a sudo git pull origin master command but it won't work because of a permission denied error from Github. There is already an ~/.ssh directory with authorized_keys, known_hosts as well as id_rsa files.

I've tried adding the keys there to my Github account and also tried using newly generated keys but it didn't work and I'm not even sure if adding these keys to my account is supposed to work. My account does have access to the repository, but I'm not sure if that is how it works.

Could anyone tell me what I need to do in order to make it possible for me to pull the code from the Github repository to this remote server?

CodePudding user response:

If you run the command with sudo, you are using credentials stored in /root.
Make sure that:

  • The command git remote -v executed in the repository folder shows you an SSH URL ([email protected]:aUser/aRepository)
  • The SSH keys are in /root/.ssh
  • The authentication work with sudo ssh -Tv [email protected].
    You should see a welcome message like:
    Hi Me! 
    You've successfully authenticated, but GitHub does not provide shell access.
    

In general, it would be better if you do all those command with a remote user account instead of the remote root account.


After discussion, it appears that:

  • sudo is not needed
  • keys are in /home/company_name
  • permissions of /home/company_name/.ssh need to be fixed

What the OP had:

-rw-r--r-- 1 [company_name] [company_name] 2.2K Mar 8 2019 known_hosts
-rw-rw-r-- 1 [company_name] [company_name] 38 Mar 8 2019 config
-rw------- 1 [company_name] [company_name] 755 Mar 17 2019 authorized_keys
-rw-r--r-- 1 [company_name] [company_name] 402 Dec 6 2019 id_rsa.pub
-rw------- 1 [company_name] [company_name] 1.7K Dec 6 2019 id_rsa
-rw-r--r-- 1 [company_name] [company_name] 746 Jun 29 08:46 id_rsa_samson.pub
-rw------- 1 [company_name] [company_name] 3.2K Jun 29 08:46 id_rsa_samson
drwx------ 2 [company_name] [company_name] 4.0K Jun 29 08:46 .
drwxr-xr-x 15 [company_name] [company_name] 4.0K Jun 29 09:20 ..

Versus the right permissions for SSH:

Path Permission
.ssh directory (code) 0700 (drwx------)
private keys (ex: id_rsa) (code) 0600 (-rw-------)
config 0600 (-rw-------)
public keys (*.pub ex: id_rsa.pub) 0644 (-rw-r--r--)
authorized_keys (code) 0644 (-rw-r--r--)
known_hosts 0644 (-rw-r--r--)

From there, a ssh -Tv [email protected] does display the expected welcome message Hi <You>! You've successfully authenticated, but GitHub does not provide shell access.

Any git clone/push/pull will work (again, no sudo needed)

  • Related