walking bear:D

隨手亂寫

random notes

2022-01-20 posted in [筆記]

github 改用 PTA 之後第一次 push post, 距離上次更新幾乎整整一年 XD

copy vim yank buffer onto command line: <CTRL-R>+<">

應該試著美化 CSS

建立LINE bot

2018-01-06: 第十八天:發布網站到 Heroku

2012-03-23: 透過 ssh 遠端存取 git repository

2013-07-13: Howto: Git Server over SSH

Git and SSH are both powerful tools, and git/ssh work well together. We introduce how to set up git server via ssh in this post. Git server through SSH is easy and fast to set up, although every user will have access to all repositories in the git server over SSH and every user is the git administrator. This is okay for a small group of git members who trust each other. But for better privilege control, you should try gitolite or gitosis.

If you need to set up a git server for multiple users which may contain contributors and administrator, you may try [[go:gitolite gitolite]] as recommended by [[set-up-git-server-through-ssh-connection/#comment-46 the gitolite author]]. You may check out [[how-to-set-up-gitolite-git-server-a-ten-minute-tutorial]] for how to set up a git server using gitolite.

If you prefer gitosis, please refer to: [[setting-up-git-server-using-gitosis]] and [[managing-repositories-on-git-server-using-gitosis]]. The gitosis proves quit stable from my experience, although it does not have as many features as gitolite.

In this post how to set up a basic git server and a more complex one (the git server is a server inside of a local area network) will be introduced. A basic git server through SSH tutorial

Table of Contents

A basic git server through SSH tutorial
    Server side git user and home
    Add id_rsa.pub to git’s .ssh/authorized_keys
    Create repository
    First commit:
    When programming:
A more complex git server through SSH tutorial
    Server side git user and home
    Add id_rsa.pub to git’s .ssh/authorized_keys
    Create repository
    First commit:
    When programming:

In this part we will build up a git server through ssh connection. We use ssh to pull or push data from or to git server. The git server can be directly connected. Suppose that we set up git server on machines example.org. Server side git user and home

logon to the git server by ssh username@example.org. username is the account name that have administrator privilege (or can sudo) on the git server. Install git package

# yum install git

Add the user for git

# useradd -m -d /home/git -u 1005 git

Configure the git user’s shell

# vim /etc/passwd

Here we assume git’s home directory is /home/git. Then we can change git’s shell from /bin/bash to /usr/bin/git-shell to forbid logging in for a shell for the git account. It can be made by editing /etc/passwd, but this is not suggested. One good method (thanks to victor) is to use the usermod command:

# usermod -s /usr/bin/git-shell git

However, there may be problem. To make this work, the /usr/bin/git-shell should be put into /etc/shells to avoid “user ‘git’ has invalid shell, rejected” error. (Thanks to Tiago for this)

In addition, COMMAND_DIR (the path “$HOME/git-shell-commands”) must exist and any of the executables in it can be invoked. The user must have read and execute permissions to the directory in order to execute the programs in it. Hence, we should create the COMMAND_DIR in git’s home and give read and execute permission to git:

# cd /home/git/
# mkdir git-shell-commands
# chmod 755 git-shell-commands

Add id_rsa.pub to git’s .ssh/authorized_keys

log on to git server, using the account that have root or sudo privilege

ssh username@example.org

Copy pub key to a temp directory

# cp .ssh/id_rsa.pub /dev/shm/

operate in git’s home as root

# cd /home/git/.ssh

backup before changing is a good habit

# cp authorized_keys authorized_keys.bak

append pub key to git’s autorized keys list

# cat /dev/shm/id_rsa.pub >> authorized_keys

Create repository

log on example.org using the account that can edit git’s files.

If you have set the git user account’s shell to git-shell on the git server, you need to add the -s /bin/bash in the su command to use bash as the shell instead of git-shell.

Create the repository directory (as the git user on server)

Initial the repository, –bare means only objects is stored on server (as the git user on server)

# su -s /bin/bash - git
$ cd ~
$ mkdir example.git
$ cd ~/example.git
$ git --bare init

First commit:

The first commit and push on local machine will create the initial repository. Initialize the local repository

$ mkdir example
$ cd example
$ git init

Add a initial empty README file

$ touch README

Add README to the repository

$ git add README

Commit the changes (adding a file)

$ git commit -m ‘first commit’

Add the remote git repository address

$ git remote add origin ssh://git@example.org/~/example.git

Push the commit to remote repository

$ git push origin master

When programming:

We need to clone the repository for one time:

$ git clone ssh://git@example.org/~/example.git

Then every time we want to edit some files:

$ cd example $ git pull # pull the newest version from the repository

After changing some files:

$ git commit -a -m ‘msg’ # commit the changes with a message msg $ git push # push the changes to the repository

A more complex git server through SSH tutorial

In this part we will build up a git server through ssh connection. We use ssh to pull or push data from or to git server. The git server is inside of a local area network. We use port forwarding to connect to it. Suppose that we set up git server on virtual machines vm111, the gateway server of the net work which vm111 is inside of is gate.example.org, and port 22111 on gate.example.org is port forwarded to vm111:22. Server side git user and home

logon to the git server by ssh username@gate.example.org -p 22111. username is the account name that can sudo on the git server.

yum install git

useradd -m -d /home/git -u 1005 git

vim /etc/passwd

Then change git’s shell from /bin/bash to /usr/bin/git-shell to forbid logging on for a shell for the git account. And remember to set the /etc/shells file (refer to the “basic git” section above). Add id_rsa.pub to git’s .ssh/authorized_keys

ssh gate.example.org -p 22111 # log on to vm111, using the account that can sudo

cp .ssh/id_rsa.pub /dev/shm/ # copy pub key to a temp directory

su -s /bin/bash - git # operate in git’s hom

$ cd /home/git/.ssh $ cp authorized_keys authorized_keys.bak # backup before changing is a good habit $ cat /dev/shm/id_rsa.pub » authorized_keys # append pub key to git’s authorized keys list

Create repository

log on gate.example.org -p 22111 # using the account that can sudo

su -s /bin/bash git

$ cd /home/git $ mkdir example.git # the repository directory $ cd example.git $ git –bare init # initial the repository, –bare means only objects is stored on server

First commit:

on local laptop:

$ mkdir example $ cd example $ git init $ touch README $ git add README $ git commit -m ‘first commit’ $ git remote add origin ssh://git@gate.example.org:22111/~/example.git $ git push origin master

When programming:

We need to clone the repository for one time:

$ git clone ssh://git@gate.example.org:22111/~/example.git

Then every time we want to edit some files:

$ cd example $ git pull # pull the newest version from the repository

After changing some files:

$ git commit -a -m ‘msg’ # commit the changes with a message msg $ git push # push the changes to the repository

// Have Fun!

some shell scripts

2021-01-31 posted in [筆記]

信用卡號檢驗

2019-11-12 posted in [筆記]

財經筆記:隨機漫步的傻瓜

2019-11-05 posted in [筆記]

Game of Thrones 權力的遊戲有沒有爛尾?

2019-11-02 posted in []

To kill a mockingbird

2019-10-28 posted in [閱讀]

The Wire - End Theme

2019-10-23 posted in []

看似無用的 Promise.resolve()

2019-10-23 posted in [筆記]

NCIS S02E02 Good wives club

2019-10-13 posted in []

The Wire - Intro Theme Songs

2019-10-11 posted in []

The Wire - S01E07 lyrics of Rolling Stones' brown sugar

2019-10-10 posted in []

JS note 使用 regex 改變單雙引號

2019-10-04 posted in [筆記]

C++ note 使用 boost iostreams 库压缩和解压数据

2019-09-27 posted in [筆記]

康斯坦丁 Constaintine

2019-09-25 posted in []

C++ note shared_ptr and enable_shared_from_this

2019-09-25 posted in [筆記]

Criminal minds 引用的名人經典句子

2019-09-14 posted in []

《日本短篇推理精選1》五斗櫃 半村良

2019-09-09 posted in []

財經筆記:未來是不可預測的

2019-09-08 posted in []

諸星大二郎:空想鳥類物語

2019-09-07 posted in []

express-session 可以不用 cookie-parser

2019-09-07 posted in []

express-session README

2019-09-05 posted in [筆記]

從 mongodb 遷移至 sqlite3

2019-09-05 posted in []

人類基因的歷史地圖 2

2019-02-19 posted in []

贝叶斯概率 - Bayesian probability

2019-01-10 posted in [筆記]

下西洋棋的機器人

2018-12-13 posted in []

黃昏流星群46關於稀有郵票的故事

2018-12-01 posted in [筆記]

javascript async programming

2018-11-24 posted in [筆記]

人狗情未了

2018-11-10 posted in []

宗像傳奇跟猴子有關的漫畫

2018-10-31 posted in []

少女偵探之怪奇事件 諸星大二郎

2018-10-30 posted in []

黃昏流星群51提到的2009數學奧林匹克第六題

2018-09-24 posted in []

千葉徹彌的童年故事

2018-09-22 posted in []

人類基因的歷史地圖

2018-09-14 posted in []

September Song

2018-09-11 posted in []

物理学家、天体物理学家伽莫夫自传

2018-06-27 posted in []

未來簡史,從智人到神人

2018-06-18 posted in []

some tv links 不解釋…電視台

2018-06-14 posted in []

不要傻傻地認為可以利用 tor 幹壞事呀!

2017-11-12 posted in [筆記]

Moravec's paradox,關於 AI 發展的悖論

2017-10-12 posted in [筆記]

奥卡姆剃刀 - Occam's Razor

2017-09-20 posted in [筆記]

夏威夷的驪歌

2017-07-13 posted in []

Shannon 經典論文的解讀

2017-07-13 posted in []

三難原則 policy trilemma

2017-07-09 posted in [筆記]

The.Good.Wife 编剧给观众关于结局的信。

2017-07-03 posted in []

《梁祝》钢琴独奏 编曲暨演奏 巫漪丽老师

2017-06-26 posted in []

俠盜一號,被最後一幕驚醒了

2017-06-23 posted in []

關於費曼,五夫人的回憶

2017-06-23 posted in []

獻給好人的奏鳴曲

2017-06-11 posted in []

關於娜烏西卡~~~宮崎駿

2017-06-09 posted in []

Relational reasoning - 關係の推理

2017-06-08 posted in [筆記]

CSS Layout - The position Property

2017-06-02 posted in [筆記]

精通 Javascript jQuery

2017-06-01 posted in []

星際效應 | Do not go gentle into that good night

2017-05-26 posted in []

網站觀察:GNU FM + GNU social

2017-05-26 posted in [筆記]

銀翼殺手:又看一遍

2017-05-24 posted in []

挖化石的小狗

2017-05-18 posted in []

網路安全:Tor的恶意应用

2017-05-17 posted in []

Node.js 的 process.nextTick() 用例

2017-05-10 posted in [筆記]

網站觀察:Komica

2017-05-09 posted in [筆記]

Javascript getter in object literal

2017-05-08 posted in [筆記]

Shrink a YouTube video to responsive width

2017-05-07 posted in [筆記]

Todo 20170506

2017-05-06 posted in []

國家地理頻道之世紀天才

2017-05-06 posted in []

A use case of Javascript tilde operator

2017-04-27 posted in [筆記]

MongoDB + Promise

2017-04-25 posted in []

WebSocket-driver + EventEmitter

2017-04-23 posted in []

一次性領100萬vs每月領5000元,哪種更划算?

2017-04-22 posted in []

居然沒想到:BvS 開頭的截圖

2017-04-18 posted in []

迷你紅白機,任天堂不賣了!

2017-04-17 posted in []

modularization of client side Javascript application

2017-04-16 posted in []

生命總能找到出路,犯人努力想上網路

2017-04-15 posted in []

黃昏流星群

2017-04-12 posted in []

新浪微博:2元女子宿舍

2017-04-11 posted in []

福爾摩斯老哥喜歡引用的話,出自嘴砲之王~王爾德

2017-04-08 posted in []

Han 的背後居然是好懷舊的中華航空包

2017-04-08 posted in []

Javascript call() & apply() vs bind()?

2017-04-05 posted in []

楊三郎美術館一遊

2017-04-05 posted in []

linux tips about sshd.service

2017-04-04 posted in []

用 git 同步幾台電腦的 repository

2017-04-02 posted in []

見底的石門水庫

2017-04-02 posted in []

人間交叉點的英文居然叫 Human Scramble

2017-04-01 posted in []

從 fedora 搬家到 debian/kali 的記錄

2017-04-01 posted in []

愚人節的網頁整理 20170401

2017-04-01 posted in [筆記]

弘兼憲史 短篇集

2017-03-31 posted in []

發文有字數限制?

2017-03-31 posted in []

「青年弘兼憲史」嘗試錯誤的軌跡 by 南 信長

2017-03-31 posted in []

測試從手機發文

2017-03-31 posted in []

利用 multiline 屏蔽掉部份 html div

2017-03-31 posted in []

用戶名不能使用中文註冊

2017-03-30 posted in []

NodeJS / Express / MongoDB - Build a Shopping Cart

2017-03-29 posted in []

Socket.io with nginx

2017-03-29 posted in [筆記]

使用 gmail 回覆登入確認程序

2017-03-29 posted in []

最近很爱看漫畫

2017-03-29 posted in []

需要美工幫忙製作圖片

2017-03-29 posted in []

關於 HTTP cookies 的解釋與奇怪應用密技

2017-03-29 posted in [筆記]

隨意【记录】一些 redis 心得

2017-03-29 posted in []

為什麼在網頁找不到發布的連結?

2017-03-29 posted in []

nodejs+socks 隨手記

2016-09-21 posted in [筆記]

一些 nodejs 隨手記

2015-12-02 posted in [筆記]

ssh over tor

2013-11-30 posted in [筆記]

firefox with tor

2013-11-29 posted in [筆記]

virtualbox with windows

2013-11-28 posted in [筆記]

patch pptpd-1.3.4 for Fedora-18

2013-01-17 posted in [程式]

架構網站的架構

2012-12-18 posted in [思考]

embed srt into mkv using ffmpeg ImageMagick

2012-10-10 posted in [程式]

犀牛書 ch15 Scripting Documents

2012-09-05 posted in [筆記]

犀牛書 jstdg6e 讀書隨記

2012-08-31 posted in [筆記]

像黑客一样写自己的技术博客

2012-08-29 posted in [筆記]

walking bear:DRSS feed

关于

wkliang

Clarke's Three Laws:

  • When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
  • The only way of discovering the limits of the possible is to venture a little way past them into the impossible.
  • Any sufficiently advanced technology is indistinguishable from magic.
  • 版权申明

    知识共享许可协议

    Fork me on GitHub

    Powered by

    Disqus, GitHub, Google Custom Search, Gravatar, HighlightJS, jekyll