3
3

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 5 years have passed since last update.

仮想hostやリモートhostからのssh

3
Posted at

ログイン先のマシンからSSH!!!

備忘録的に書きます。

ログイン先からGitを利用する、さらに他の端末へSSHする際など、毎回鍵を作っていませんか?
No more 鍵だらけの生活

現在接続中の秘密鍵を利用する方法があります。
一般的なvagrant(仮想VM)での設定を例にしましょう

設定ファイル

~/.ssh/config
Host node1
  HostName 127.0.0.1
  User vagrant
  Port 2001
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/himinato/.ssh/mykey_rsa
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes # <- これな

ForwardAgentを設定する事により、接続先から現在接続している秘密鍵(この例ではmykey_rsa)を利用してssh接続をすることができます。

ssh-agent

あまり詳しいことは分かりませんがSSHではssh-agentという認証鍵を管理してくれるやつがいたそうな。
そいつにssh-addすることによって鍵を管理してくれるからパスワード入力などを省略できるらしい。
もちろん設定ファイルからではなく、コマンドからでもいける

$ ssh-add .ssh/your-key

まとめ

何がうれしいかというとローカルで使うssh鍵の公開鍵をgithubなどに登録しておけば、リモート接続先から不要な鍵の登録なく使える点だろう。

sshには今回紹介したForwardAgentとは別にport forward機能もあり、それがAWSのRDSに接続する際に利用出来ることはまた別の話

便利なんで使ってみて。(最近AnsibleやCapistrano使いはじめて知りました)

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?