Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:37:56+00:00 2026-06-15T05:37:56+00:00

This is my first post here, so please bear with me… I have discovered

  • 0

This is my first post here, so please bear with me…

I have discovered the amazing powers of .ssh/config after having fully configured my .bash_aliases file, and as I’m pretty lame with programming, I was looking for a nice way to parse the connection details from the bash_aliases file into the ~/.ssh/config file.

So, going into details, my bash_aliases looks like this:

alias serverA='ssh -i ~/.ssh/serverA.key -o $SRVR_ALV user@serverAhostname'
alias serverB='ssh -i ~/.ssh/serverB.key -o $SRVR_ALV user@serverBhostname'
....

Where I have defined a variable for ServerAliveInterval in $SRVR_ALV.

My intention is to parse that entry into this and in the meantime get rid of that ugly variable

Host serverA
HostName serverAhostname
IdentityFile ~/.ssh/serverA.key

Host serverB
.....

What do you think is the best way to perform this? I was looking for a nice bash script, or perhaps using vi capabilities.
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:37:59+00:00Added an answer on June 15, 2026 at 5:37 am

    How about some Perl?

    perl -ne "/^alias (.*)='ssh -i (.*) -o (.*) (.*)\@(.*)'/ and 
        print qq{Host \$1\nHostName \$5\nIdentityFile \$2\n\n}" < \
     ~/.bash_aliases
    

    If you like what you see, redirect it to append to >> ~/.ssh/config

    [Update] – an explanation for the non-Perl user as to what’s going on:

    perl -ne: -e means, ‘The next argument is the script to (e)xecute’.
    -nmeans, '*run the given script once per line*' - so-necan sort-of
    emulate
    sed`.

    The perl code:

    /^alias (.*)='ssh -i (.*) -o (.*) (.*)\@(.*)'/ and 
    print qq{Host \$1\nHostName \$5\nIdentityFile \$2\n\n}
    

    reads: for only the lines that match the regexp /^alias ../, print a string (qq{...} is that same as "..." in Perl), and the interpolated variables "\$1", "\$4" etc are the result of what was captured in the regexp.

    perl -ne expects input, which comes from < ~/.bash_aliases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here. I have a problem. I need to take
First post here, so please bear with me if I get something wrong. I'm
This is my first post so please bear with me with inputting the code
This is my first post here so please forgive any protocol errors. My question
Well, this is my first post here and really enjoying the site. I have
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post, so please bear with me. I'll try and be
Okay this is my first post here so please forgive me if i mess
This is my first post in any forum so please bear with me. I
This is my first post here so go easy. I am trying to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.