0
0

さくらレンタルサーバーからBitbucketにSSH接続するための手順

Posted at

さくらレンタルサーバーを使った例。
リポジトリをHTTPS接続ではなく、SSH接続で管理したい

備忘録のため殴り書きです

レンタルサーバーで鍵を作る

レンタルサーバーにSSHで接続する

$ ssh {ユーザー名}@{ホスト名}

鍵を作成

ユーザーのホームディレクトリにある.sshをカレントディレクトリとして

$ ssh-keygen -t rsa
  1. 任意のファイル名を聞かれる
  2. パスフレーズを聞かれる
  3. パスフレーズの確認

{任意のファイル名} = 秘密鍵ファイル
{任意のファイル名}.pub = 公開鍵ファイル
の2ファイルができる。

Bitbucketのリポジトリに設定する

  1. リポジトリのRepository settings/セキュリティ/アクセスキーにアクセス
  2. Add Keyから、作成した公開鍵ファイルの中身コピペし設定

レンタルサーバーからBitbucketにSSHで接続する

レンタルサーバーの.ssh/configファイル(なければ作る)に以下を記述

Host bitbucket.org
 HostName altssh.bitbucket.org
 User git
 Port 443
 IdentityFile ~/.ssh/{秘密鍵ファイル}
 TCPKeepAlive yes
 IdentitiesOnly yes

接続確認

git fetchコマンドなどで対象のリポジトリが接続できているか確認

その他

HTTPSで接続していたリポジトリについて

git remote get-url originでHTTPSとなっていたら以下の通り変更する

git remote set-url origin git@bitbucket.org:{ワークスペース/リポジトリ名}.git

(Bitbucketの対象リポジトリのcloneする時のものを指定するで良い)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0