Quickly build a git + ssh-based server on linux

Source: Internet
Author: User
Create a git account on the host so that everyone who needs write permission can send an SSH public key and add it to ~ Sshauthorized_keys file. In this way, everyone will access the host through the git account. This does not affect the submitted data.

Create a git account on the host so that everyone who needs write permission can send an SSH public key and add it to ~ /. Ssh/authorized_keys file. In this way, everyone will access the host through the git account. This will not affect the submitted data-the identity used to access the host will not affect the submitted object information.

Step 1: Create a user on the server (git)

# Sudo addusergit

Step 2: The client generates the public key and

Create a public key: ssh-keygen,

View the generated public key and private key pair in the user directory of the client.

# Cd ~ /. Ssh

# Ls

id_dsa        id_dsa.pub

The directory where the public key is located: windows is in the "C:/User/username/. ssh" directory, linux is in "~ /. Ssh ",~ Representative user directory

Step 3: add the public keys of each user under the git User server and configure the ssh service

Append the public key files of each user to the authorized_keys file of the git User on the server.

$ cat  id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat  id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat  id_rsa.jessica.pub >> ~/.ssh/authorized_keys
Modify the permissions of. ssh and authorized_keys). if you forget the following, the password will be entered every time (ps, it has been stuck for a long time)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Step 4: Create a git library under a git User

Cd gitDIR

Mkdir project. git

Cd project. git

Git init-bare

Step 5: Use the client

Submit your own database

Mkdir project

Cd project

Git init

Vi first.txt

Git remote add origin gitserver/gitDIR/project. git

Git push origin master

Clone: git clonegit @ gitserver/gitDIR/project. git

Step 6: restrict developer login

By default, users who can connect to the git server can also log on to the server through ssh directly, so the server may have the risk of being logged on by multiple users. the restricted method is as follows:

Vi/etc/passwd

Git: x: 1000: 1000:/home/git:/bin/sh

The row is modified as follows:

Git: x: 1000: 1000:/home/git:/bin/git-shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.