fzf + SSH Config Hosts

󰃭 2024-10-10

SSH has a nice feature in which you can store aliases for frequently accessed hosts.

Combining this with fzf, you can have a nice quick shortcut to quickly pick a server to connect to into.

This comes in very handy if you need to ssh into different servers and forget their IP or hostname often.

Here’s a sample ssh config file (normally located at ~/.ssh/config):

# see https://man.openbsd.org/ssh_config.5 for all the available configuration settings
Host runner-staging
    HostName 10.0.0.8
    User alpha

Host runner-production
    HostName 10.0.0.9
    User beta

Host mainframe
    HostName mainframe.computer.world
    User hackerman

Here’s a small shell function which calls fzf with the hostnames configured and allows you to pick one to connect to:

s () {
  local server
  server=$(grep -E '^Host ' ~/.ssh/config | awk '{print $2}' | fzf)
  if [[ -n $server ]] then
    ssh $server
  fi
}

Add this function to your .bashrc (or .zshrc, or whichever config file for your shell) and reload the configuration.

Now, you can quickly ssh into mainframe by typing s:

$ s

# fzf will allow to quickly search and pick your server
> runner-staging
  runner-production
  mainframe
  3/3 ──────────

# press enter and you will be connected!
[hackerman@mainframe.computer.world ~]$ 


More posts like this

Publishing an App on F-Droid

󰃭 2021-08-03 | #android #f-droid #tips #tutorials

I made some small apps for Android and I wanted to distribute them. I also care a lot about software freedom, so F-Droid is the best place for me to publish my apps. Disclaimer! You are not able to sell your app on F-Droid. If you want to make money with it, you would need to allow users to pay through another method. Please see this StackExchange question if you’re interested in monetization.

Continue reading 


How to use Let's Encrypt certificates with Keycloak

󰃭 2023-01-04 | #java #keycloak #letsencrypt #linux #tips #tutorials

Keycloak provides user federation, strong authentication, user management, fine-grained authorization, and more. Here is a guide to enable HTTPS access to your Keycloak server using a free Let’s Encrypt SSL certificate. The beauty of Let’s Encrypt is its ease of use and the fact that it’s free! This guide assumes you have already installed Keycloak at /opt/keycloak/ using the official guide for bare metal installs, and now you want to enable HTTPS access.

Continue reading 