TL;DR
Mac->UbuntuのSSHの備忘録です。
図書館用に443(HTTPS)も開けています。
クライアントの設定(Mac)
項目 | コマンド |
---|---|
ディレクトリの作成 | mkdir ~/.ssh/ |
キーの作成 | cd ~/.ssh/ ssh-keygen -t rsa #パスフレ無し |
config作成 | vim ~/.ssh/config #以下の設定内容を貼り付け |
パーミッションの変更 | sudo chmod -R 700 ~/.ssh/ sudo chmod 600 ~/.ssh/id_rsa |
公開鍵コピー | cat ~/.ssh/id_rsa.pub |
クライアントのconfigの設定内容
config
# server
Host blog
HostName 123.456.789.012
Port 22 #or 443
IdentityFile ~/.ssh/id_rsa
User john
Protocol 2
ServerAliveInterval 15
ServerAliveCountMax 10
# gitlab
Host gitlab
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa
サーバーの設定(Ubuntu)
項目 | コマンド |
---|---|
ポート開放 | sudo ufw allow 22/tcp |
ポート開放(HTTPS) | sudo ufw allow 443/tcp |
Firewallの有効化 | sudo ufw enable |
ディレクトリの作成 | mkdir ~/.ssh/ |
ファイルの移動 | cd .ssh |
キーの追加 | cat ~/id_rsa.pub >> authorized_keys |
公開鍵の削除 | rm ~/id_rsa.pub |
パーミッションの変更 | sudo chmod -R 700 ~/.ssh/ sudo chmod 600 ~/.ssh/authorized_keys |
SSHd側で443ポートの追加
項目 | コマンド |
---|---|
複数ポートでlisten | sudo vi /etc/ssh/sshd_config # Port 443を追加する |
再起動 | sudo shutdown -r now |
開放しているポートの確認 | sudo lsof -i -nP # 443でlistenしてればOK |
テスト(Mac)
項目 | コマンド |
---|---|
普通に接続 | ssh -i ~/.ssh/id_rsa john@123.456.789.012 |
configで接続 | ssh blog |
設定ファイルを明示的に読み込んで接続 | ssh -F ~/.ssh/config blog |
REMOTE HOST IDENTIFICATION HAS CHANGEDの時 | ssh-keygen -R 123.456.789.012 # ホストをknown_hostsファイルから削除 |
テスト(リポジトリ)
項目 | コマンド |
---|---|
接続テスト | ssh -T git@github.com |
アップストリームのorigin削除 | git remove origin master |
アップストリームのorigin追加 | git remote add origin git@github.com:{userName}/{repositoryName}.git |
関係ないがオレオレ証明書のmemo
terminal
$ openssl genrsa 2048 > server.key
$ openssl req -new -key server.key > server.csr
$ openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt
参考文献
http://runble1.com/ubuntu-config-ssh/
http://superbrothers.hatenablog.com/entry/20090730/1248971671
http://serverfault.com/questions/518729/cygwin-ssh-issue-could-not-resolve-hostname-awshost1-hostname-nor-servname-pro
http://www.unixuser.org/~euske/doc/openssh/jman/ssh_config.html
http://qiita.com/tag1216/items/5d06bad7468f731f590e
http://d.hatena.ne.jp/ozuma/20130511/1368284304