LoginSignup
4

More than 5 years have passed since last update.

SSH Config で * を使用するときは順番に気をつけたほうがいい

Posted at

SSH Config を記述するときに * を使うと冗長な記述をまとめることが出来て便利だが、記述する順番を間違えると意図したとおりに動作しないことがあるので注意が必要。

~/.ssh/config
Host *
  User foo

Host example
  User bar
  HostName example.com

この設定は一見「デフォルトのユーザー名が foo で、ホストが example のときは bar というユーザーでログインする」という設定に見えるが、この設定で ssh example すると ssh foo@example.com と同じになる。

SSH Config では 先にマッチしたほうが優先される ので、意図したとおりに動作させるには以下のように設定する。

~/.ssh/config
Host example
  User bar
  HostName example.com

Host *
  User foo

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
4