List SSH Config Host

In SSH configuration files, you can define multiple hosts with different settings. To list all the defined hosts in your SSH config file using the sed command, you can use the following command:

1
2
```bash
sed -n '/^#/!s/Host //p' ~/.ssh/config

Here's what this command does:

- `sed` is a stream editor for filtering and transforming text.
- `-n` tells `sed` to suppress automatic printing.
- `/^#/!s/Host //p` is a `sed` expression:
  - `/^#/` matches lines that start with `#`, which are comments in the SSH config file.
  - `!` negates the match, so it selects lines that do not start with `#`.
  - `s/Host //` replaces the word "Host" with an empty string, effectively removing it from the line.
  - `p` instructs `sed` to print the modified lines.

When you run this command, it will display a list of host names defined in your SSH config file, excluding any commented-out entries. This can be useful to quickly see the configured hosts on your system.
0%