SSH

鍵作成

ssh-keygen -t rsa

ssh keyを生成するときには idをしていするのがいい

ssh-keygen -t rsa -C "ここのテキストは.pubに入る"

Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa): id_rsa_your_id
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_your_id.
Your public key has been saved in id_rsa_your_id.pub.
The key fingerprint is:

config

keyの指定

Host host1.xxx
    User ssh_user
    IdentityFile ~/.ssh/xxx_rsa
Host host1.xxx host2.xxx
    User ssh_user
    IdentityFile ~/.ssh/xxx_rsa

接続

port指定

ssh root@sv10.sixcore.ne.jp -p 2222

多段ssh

image

  • 踏み台マシンを経由する必要がある
  • 踏み台マシンへのログインすら、特定範囲のIPアドレスからしか受け付けてくれない

の時に踏み台サーバに接続が面倒なので 多段sshを使う

host gateway
   HostName sshgate.hoge
   User hoge

Host RemoteHost-out
  HostName RemoteHost
  User fuga
  ProxyCommand ssh -W %h:%p gateway

以下のcommandで接続 ssh RemoteHost-out

ProxyCommand

netcat

ProxyCommand ssh server nc %h %p

ssh -W

ProxyCommand ssh -W %h:%p server

agent forwarding

agent forwarding setting

~/.ssh/config

Host *example.com
  ForwardAgent yes

ssh loginの自動化

#!/bin/sh

PW="Password"

expect -c "
set timeout 5
spawn env LANG=C /usr/bin/ssh hoge@ServerName
expect \"password:\"
send \"${PW}\n\"
expect \"$\"
exit 0
"

TODO

このリンクもうちょっと整理

login際にpassword省略

authorized_keysにpubキーの内容を入れる

chmod 700 .ssh
chmod 600 .ssh/*

References

results matching ""

    No results matching ""