Skip to Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

6.12. Tailoring SSH per Host

Problem

You want to simplify a complicated SSH command line, or tailor SSH clients to operate differently per remote host.

Solution

Create a host alias in ~/.ssh/config:

               ~/.ssh/config:
Host mybox
        HostName mybox.whatever.example.com
        User smith
        ...other options...

Then connect via the alias:

$ ssh mybox

Discussion

OpenSSH clients obey configurations found in ~/.ssh/config. Each configuration begins with the word Host followed by an hostname alias of your invention.

Host work

Immediately following this line, and continuing until the next Host keyword or end of file, place configuration keywords and values documented on the ssh(1) manpage. In this recipe we include the real name of the remote machine (HostName), and the remote username (User):

Host work
        HostName mybox.whatever.example.com
        User smith

Other useful keywords (there are dozens) are:

IdentityFile ~/.ssh/my_alternate_key_dsa           Choose a private key file
Port 12345                                         Connect on an alternative port
Protocol 2                                         Use only the SSH-2 protocol

See Also

ssh_config(5) defines the client configuration keywords.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Linux Security Cookbook - Second Edition

Practical Linux Security Cookbook - Second Edition

Tajinder Kalsi
Mastering Linux Command Line

Mastering Linux Command Line

Coding Gears | Train Your Brain

Publisher Resources

ISBN: 0596003919Errata Page