openSUSE Leap 16

Git : SSH でアクセスする2025/12/24

 

こちらの [2] の例ように ローカル to ローカル ではなく、 あるホスト上の作業ディレクトリから、リモートホスト上に存在する Git リポジトリにアクセスする場合は、手段は様々ありますが、 SSH でアクセスすることもできます。

[1]

Git リポジトリが存在するホスト上で SSH サーバーが稼働していることが前提です

[2] 例として、こちらの [2] で作成した [dlp:srv.world/home/suse/project.git] リポジトリに SSH でアクセスします。
当例のような共有ではないリポジトリの場合は、リポジトリを作成したユーザーと同じ UID を持ったユーザーでアクセスする必要があります。
suse@node01:~>
mkdir work

suse@node01:~>
cd work
# SSH アクセスでリポジトリを複製

suse@node01:~/work>
git clone ssh://suse@dlp.srv.world/home/suse/project.git

Cloning into 'project'...
(suse@dlp.srv.world) Password:   # 接続ユーザーのパスワード (鍵ペアをセットしている場合は不要)
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (5/5), done.

suse@node01:~/work>
cd project

suse@node01:~/work/project>
total 8
-rw-r--r--. 1 suse suse 9 Dec 24 09:01 testfile1.txt
-rw-r--r--. 1 suse suse 9 Dec 24 09:01 testfile2.txt

# 名前とメールアドレス設定

suse@node01:~/work/project>
git config --global user.name "Server World"

suse@node01:~/work/project>
git config --global user.email "serverworld@node01.srv.world"

suse@node01:~/work/project>
echo test >> testfile1.txt

suse@node01:~/work/project>
git commit testfile1.txt -m "Update testfile1.txt"

[master 92ce325] Update testfile1.txt
 1 file changed, 1 insertion(+)

suse@node01:~/work/project>
git remote -v

origin  ssh://suse@dlp.srv.world/home/suse/project.git (fetch)
origin  ssh://suse@dlp.srv.world/home/suse/project.git (push)

suse@node01:~/work/project>
git push origin master

(suse@dlp.srv.world) Password:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 298 bytes | 298.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://dlp.srv.world/home/suse/project.git
   b81fa39..92ce325  master -> master
関連コンテンツ