Categories
Programs IT Support

List the hosts in .ssh /config file, then ssh directly

This is a script to help you to ssh when you set many hosts in ssh .config file. I made Windows Powershell and Linux bash version scripts.

How to use

command: sshfc [Part of the host name]

If you type only sshfc, all hostnames set in the config file will be displayed.

If you type “sys” with the first argument, hostnames including “sys” will be displayed.

You can connect the host with ssh by selecting a number which is shown next to the hostname.

The command name is sshfc with the head of “ssh from .config”.

An example of use as follows.

C:> sshfc sys
1) system
2) test_system
3) dev_system
Press the number of the host to ssh. Press [c] if you want to cancel.'
: 3
ssh dev_system
hogehoge@192.168.1.100's password:
....

Install Windows Powershell version

Make bin folder and Add the folder to your PATH. And download the script file from Github and put the file under the bin folder.

New-Item ($HOME + "\bin") -ItemType Directory
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";%USERPROFILE%\bin", "User")

git clone https://github.com/y-toy/windows_sshfc.git
cd windows_sshfc
Move-Item ./sshfc.ps1 ($HOME + "\bin")

Note

Try the following command if you are unable to run the script. This will loosen the restrictions of the script execution.

Set-ExecutionPolicy Unrestricted -scope CurrentUser

Install Linux Bash version

Download the script file from Github and move the file under PATH folder.

git clone https://github.com/y-toy/linux_sshfc.git
chmod +x ./linux_sshfc/sshfc
mv ./linux_sshfc/sshfc /usr/local/bin/

Note

I have recently changed my Windows ssh client to “Windows terminal” from Microsoft. The “Windows terminal” itself is excellent, but it is difficult to use when I select the destination of the SSH connection from ssh config file. I made this tool to cover the problem.

Since the tool I made was unexpectedly useful, I made the bash version so that I can use the “sshfc” command after entering the server as well.
Now I don’t have to think “What’s the hostname I set in my config file?”.