差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
linux:open_ssh:client [2015/06/13 04:44] – [公開/秘密キーのペアの生成] ともやん | linux:open_ssh:client [2019/02/16 21:35] (現在) – 削除 ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== ssh クライアントの使い方 ====== | ||
- | ===== 単純に接続 ===== | ||
- | < | ||
- | $ ssh user_name@server_name.com | ||
- | </ | ||
- | |||
- | ===== ポートを指定して接続 ===== | ||
- | < | ||
- | $ ssh user_name@server_name.com -p22022 | ||
- | </ | ||
- | |||
- | ===== 接続先へポートフォワード ===== | ||
- | ローカルの8080ポートへの要求をリモートのlocalhost: | ||
- | < | ||
- | $ ssh user_name@server_name.com -L10080: | ||
- | </ | ||
- | \\ | ||
- | ローカルの1022ポートへの要求をリモートの192.168.1.1: | ||
- | < | ||
- | $ ssh user_name@server_name.com -L1022: | ||
- | </ | ||
- | |||
- | ===== 公開/ | ||
- | * Linux or Mac では ssh-keygen を使用する。< | ||
- | $ ssh-keygen -t ecdsa -b 521 -C " | ||
- | </ | ||
- | * Linux or Mac では ssh-keygen を使用して、RSA(ssh v2)形式の公開/ | ||
- | $ ssh-keygen -t rsa -C " | ||
- | Generating public/ | ||
- | Enter file in which to save the key (/ | ||
- | Enter passphrase (empty for no passphrase): | ||
- | Enter same passphrase again: <- 確認用のパスワードを入力 | ||
- | Your identification has been saved in / | ||
- | Your public key has been saved in / | ||
- | The key fingerprint is: | ||
- | 2f: | ||
- | The key's randomart image is: | ||
- | +--[ RSA 2048]----+ | ||
- | | | | ||
- | | | | ||
- | | . | | ||
- | | | ||
- | | o S. | | ||
- | | ..o=.. | ||
- | | . o o=++ . | | ||
- | | E . +.+=.o | ||
- | | | ||
- | +-----------------+ | ||
- | </ | ||
- | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
- | @ | ||
- | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
- | Permissions 0777 for '/ | ||
- | It is recommended that your private key files are NOT accessible by others. | ||
- | This private key will be ignored. | ||
- | bad permissions: | ||
- | Permission denied (publickey, | ||
- | </ | ||
- | $ chmod 600 ~/ | ||
- | </ | ||
- | |||
- | ===== 公開キーの登録 ===== | ||
- | - 公開キーは接続先のサーバーに転送しておく。< | ||
- | $ scp -P 22022 ~/ | ||
- | id_rsa.pub | ||
- | </ | ||
- | - サーバー上でへ公開キーを登録する。< | ||
- | $ cat ~/ | ||
- | </ | ||
- | $ sudo chown tomoyan.tomoyan ~/.ssh -R | ||
- | $ sudo chmod 700 ~/.ssh | ||
- | $ sudo chmod 600 ~/ | ||
- | </ | ||
- | $ ssh -i ~/ | ||
- | Identity added: / | ||
- | Permission denied (publickey, | ||
- | </ | ||
- | |||
- | ===== 秘密キーを指定して接続 ===== | ||
- | 秘密キーを複数使い分ける場合は、-i オプションで秘密キーを指定する。(標準では ~/ | ||
- | $ ssh -i ~/ | ||
- | </ | ||
- | ※秘密キーは自分だけがアクセスできるように設定しておく | ||
- | < | ||
- | chmod 600 ~/ | ||
- | </ | ||
- | |||
- | ===== 秘密キーのパスフレーズ変更 ===== | ||
- | < | ||
- | $ ssh-keygen -p -f .ssh/id_rsa | ||
- | Enter old passphrase: <- 古いパスフレーズを入力 | ||
- | Key has comment ' | ||
- | Enter new passphrase (empty for no passphrase): | ||
- | Enter same passphrase again: <- 新しい確認用パスフレーズを入力 | ||
- | Your identification has been saved with the new passphrase. | ||
- | </ | ||
- | |||
- | ===== 接続オプションを省略 ===== | ||
- | 接続先の設定を簡単に呼び出せるようにするために、ユーザー毎の設定ファイルを記述することができる。\\ \\ ~/ | ||
- | Host tomoyan.net | ||
- | HostName | ||
- | Port 22022 | ||
- | User tomoyan | ||
- | GatewayPorts | ||
- | LocalForward | ||
- | IdentityFile | ||
- | </ | ||
- | |||
- | ===== sudo で Agent Forward する方法 ===== | ||
- | sudo の設定ファイルに env_keep の設定を追記する。 | ||
- | < | ||
- | $ sudo vi sudo | ||
- | </ | ||
- | 以下を追記する。 | ||
- | < | ||
- | Defaults | ||
- | </ |