ユーザ用ツール

サイト用ツール


ssh

ssh

公開鍵認証

sshdを公開鍵認証のみ受け付ける設定にする

Protocol 2

# 鍵認証を有効にする(RSAAuthenticationはssh v1用の設定なので不要)
RSAAuthentication no
PubkeyAuthentication yes

# チャレンジレスポンス認証
ChallengeResponseAuthentication no

# パスワード認証
PasswordAuthentication no

# PAM
UsePAM no

その他の設定

# SSHの待ち受けポート、22以外に変更すると攻撃はほとんど無くなる
Port 22222

# rootユーザのログインを許可
PermitRootLogin no

# 空パスワード許可
PermitEmptyPasswords no

# 権限の分離、sshdの実行ユーザ(rootユーザ)ではない子プロセスを作成してシェルを実行
UsePrivilegeSeparation yes

# ssh可能なユーザを制限
AllowUsers nullpon
DenyUsers xxxxx

ホストベース認証

サーバ同士を公開鍵で認証し、その上のユーザが同じ名前ならば認証をスキップできる。

ssh config

~/.ssh/config によく使うサーバの設定を入れておくと便利

Host dev1
  Hostname 10.200.3.11
  User your_login_account
  
Host dev2
  Hostname 10.200.3.12
  User your_login_account

Host gh
  Hostname gh
  User git

scpでサーバからファイルをコピー

$ scp dev1:~/hoge.txt ./

sshログイン

$ ssh dev2

githubからリポジトリをクローン

$ git clone gh:nodejs/node.git

ssh-keygen

ポートフォワーディング

ssh -f -N -L 26379:redis.internal:6379 bastion
  • -f: バックグラウンド実行
  • -N: リモートでコマンドを実行しない

鍵転送

ローカルの秘密鍵を接続先でも使えるようにする

まずssh-agentを起動(macは常に起動しているので不要)

eval "$(ssh-agent -s)"

鍵を追加

ssh-add ~/.ssh/id_ed25519

macでは.ssh/configで鍵を追加するように設定しても良い

Host nullpon.moe
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

接続

ssh -A user@nullpon.moe
ssh.txt · 最終更新: 2023/06/29 02:55 by nullpon