0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ssh接続の手順【OSの授業】

Last updated at Posted at 2023-10-16

目的

大学の学科サーバーにpassword入力抜きで二重暗号鍵でssh接続できるようにしたい。

環境

シェル:zsh

設定方法

1. ssh keyを作成

ssh-keygen

keyのパスワードはなしでもok。
~/.ssh/id_rsa(秘密鍵) と ~/.ssh/id_rsa.pub(公開鍵) が生成される。

2. ~/.ssh/config の設定

~/.ssh/configに以下を追記する。

Host 設定するホスト名
    Port xxxx
    User ユーザー名
    Hostname 学科サーバーのホスト名

それぞれ自分で編集する。

3. 学科サーバーへ公開鍵を転送して登録

学科サーバーへの公開鍵を転送と公開鍵登録が実行する。

ssh-copy-id -i ~/.ssh/id_rsa.pub ユーザー名@設定したホスト名

正しく設定されていることを確認する。(Identity added: 〜 と返ってくればok)

ssh-add ~/.ssh/id_rsa

※これは ~/.ssh/id_rsa.pub 中身を学科サーバーの ~/.ssh/authorized_keys に追加している。(下記コマンドは入力不要)

ssh 学科サーバーのホスト名 "mkdir ~/.ssh; chmod 700 ~/.ssh "
cat  ~/.ssh/id_rsa.pub | ssh 学科サーバーのホスト名 "cat >> ~/.ssh/authorized_keys"

4. パスワードなしでssh接続できるか確認

パスワードを入力することなく、datels が実行できることを確認する。

ssh 設定したホスト名 "date ; ls -ld ~"

これにてssh接続完了。

sshのホスト名をtab補完できるようにする

~/.zshrcの最後に以下を追記。

function _ssh {
  compadd `fgrep 'Host ' ~/.ssh/config | awk '{print $2}' | sort`;
}

zshを再読み込み。

source ~/.zshrc

ssh 半角スペース + tabキー で補完が出れば成功。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?