How to configure SSH Client in Linux ? - GeeksforGeeks (2024)

Last Updated : 28 Mar, 2022

Summarize

Comments

Improve

At times we may need to access multiple remote systems with different IP addresses/hostnames, usernames, non-standard-ports with various command-line options. One way is to create a bash alias for each remote connection. But we have an easy and much better solution to this problem. OpenSSH allows to create per-user configuration file to store different SSH options for each remote server. In this article, we will see the basics of SSH Client configuration with some examples.

Requirement

Linux or macOS system with OpenSSH Client installed.

File Location

The SSH client-side configuration file is named config which is stored in the .ssh directory under the user’s home directory. By default, the config file will not be present and the user needs to create it using the touch command. This file should be readable and writable only by the user and should not be accessed by others.

Config File Syntax

SSH config file takes the following syntax,

Host [Alias1] Option1 [value] Option2 [value] Option3 [value] Host [Alias2] Option1 [value] Option2 [value] Host [Alias3] Option1 [value]

SSH Client reads the configuration file stanza by stanza. If more than one pattern matches, then the options from the first matching stanza take precedence. Hence, the host-specific declaration should come first and the generic declaration should be kept last.

SSH Client does not care about indentation but it’s recommended for readability.

There is numerous number of ssh options available which can be found by typing man ssh_config in Linux terminal or can check in /etc/ssh/ssh_config file for reference.

SSH Config File Example

When a user wants to connect to a remote server through ssh, then he should mention remote username followed by IP address or hostname and port (default port 22 can be ignored). Consider below example,

How to configure SSH Client in Linux ? - GeeksforGeeks (2)

Access server

Now, we can have the below lines in ~/.ssh/config file,

How to configure SSH Client in Linux ? - GeeksforGeeks (3)

Sample Config

If we simply type ssh server, the ssh client will read the configuration file and use the options mentioned to connect to the remote server.

How to configure SSH Client in Linux ? - GeeksforGeeks (4)

Access server via client config

SSH Config Patterns

The host directive mentioned in syntax can contain one pattern or space-separated list of patterns.

Host nancy serverWorking Patternsnancy, server 

Patterns can contain one of the following specifiers as well,

  • * – Matches zero or more characters.
Host nancy* Working Patternsnancy,nancy123,nancy-server,etc 
  • ? – matches exactly one character.
Host nancy? Working Patternsnancy1, nancy2, nancy3, etc
  • ! – When used at the start of a pattern, it negates the match.
Host nan* !nancy Working Patternsnan-1, naneo, etc [nancy will not work]

SSH Config Precedence

Let’s consider the below example to understand more about the precedence in ssh options when multiple hosts are defined,

Host nancy HostName 10.21.43.150 Compression noHost jancy HostName 10.2.33.58 PermitLocalCommand noHost trial HostName 10.2.33.57 PermitLocalCommand yes Host *cy !jancy User woot Port 22 Host * User root Port 22 Compression yes
  • When a user types ssh nancy, the ssh client applies the options from the first match which is Host nancy. Then it checks for the next matching pattern which is Host *cy !jancy. Then the next matching pattern is Host *, here none of the options are considered as they got over-ridden in the earlier matched patterns. The full list of options are,
Host nancy HostName 10.21.43.150 User woot Port 22 Compression no

How to configure SSH Client in Linux ? - GeeksforGeeks (5)

  • When a user types ssh jancy, the matching patterns are Host jancy and Host *. The options used are,
Host jancy HostName 10.2.33.58 Port 22 User root Compression yes PermitLocalCommand no

How to configure SSH Client in Linux ? - GeeksforGeeks (6)

  • When the user types ssh trial, the matching patterns are Host trial and Host *,
Host trial HostName 10.2.33.57 PermitLocalCommand yes User root Port 22 Compression yes

How to configure SSH Client in Linux ? - GeeksforGeeks (7)

  • For all other remote connections, the ssh client will use Host *cy !jancy and Host *.

Override SSH Config File Options

SSH client reads the configuration file in the following order,

  • Options are mentioned in the command line.
  • Options mentioned in the ~/.ssh/config file.
  • Options mentioned in the /etc/ssh/ssh_config file.

How to configure SSH Client in Linux ? - GeeksforGeeks (8)

Now if the user wants to connect to amp150.arubathena.com but with a different user, then it can be over-ridden in the command line as below,

How to configure SSH Client in Linux ? - GeeksforGeeks (9)


K

strive_to_learn

How to configure SSH Client in Linux ? - GeeksforGeeks (10)

Improve

Previous Article

TELNET and SSH in Cisco devices

Next Article

AAA (Authentication, Authorization and Accounting) configuration (locally)

Please Login to comment...

How to configure SSH Client in Linux ? - GeeksforGeeks (2024)
Top Articles
Manulife Financial Stock Forecast & Predictions: 1Y Price Target $40.00 | Buy or Sell NYSE: MFC 2024
How High Can Ripple's (XRP) Price Go After the $125 Million Fine? (Top Analyst Predictions)
Cranes For Sale in United States| IronPlanet
Canary im Test: Ein All-in-One Überwachungssystem? - HouseControllers
T Mobile Rival Crossword Clue
Polyhaven Hdri
Costco The Dalles Or
Wild Smile Stapleton
Free Robux Without Downloading Apps
Whiskeytown Camera
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Thayer Rasmussen Cause Of Death
Cvs Learnet Modules
Athens Bucket List: 20 Best Things to Do in Athens, Greece
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Video shows two planes collide while taxiing at airport | CNN
Van Buren County Arrests.org
Fsga Golf
Wnem Tv5 Obituaries
The best brunch spots in Berlin
Renfield Showtimes Near Paragon Theaters - Coral Square
Vera Bradley Factory Outlet Sunbury Products
Jurassic World Exhibition Discount Code
A Man Called Otto Showtimes Near Carolina Mall Cinema
Possum Exam Fallout 76
Primerica Shareholder Account
Otis Offender Michigan
Word Trip Level 359
Scioto Post News
One Credit Songs On Touchtunes 2022
Appraisalport Com Dashboard /# Orders
Chris Provost Daughter Addie
Foolproof Module 6 Test Answers
Watchseries To New Domain
Laff Tv Passport
National Insider Threat Awareness Month - 2024 DCSA Conference For Insider Threat Virtual Registration Still Available
Craigslist Ludington Michigan
Indio Mall Eye Doctor
Lake Andes Buy Sell Trade
All Obituaries | Sneath Strilchuk Funeral Services | Funeral Home Roblin Dauphin Ste Rose McCreary MB
Sun Tracker Pontoon Wiring Diagram
The Conners Season 5 Wiki
Tricia Vacanti Obituary
3 Zodiac Signs Whose Wishes Come True After The Pisces Moon On September 16
Chubbs Canton Il
R/Gnv
Laura Houston Wbap
Acuity Eye Group - La Quinta Photos
Greg Steube Height
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
Https://Eaxcis.allstate.com
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 6210

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.