Alasdair Macintyre

Freelance Web Developer based in Manchester, UK

  • Home
  • About
  • Github
  • Facebook
  • Instagram

SSH Snippets

Posted by Alasdair Macintyre on January 8, 2012
Posted in: Uncategorized.

Keypairs and Authorized Keys

To generate a keypair on the client computer:

ssh-keygen -t dsa

This creates the files ~/.ssh/id_dsa and id_dsa.pub (you can set a passphrase but then you’d need to type it in every time you wanted to use it). To add this key to the servers you want to log in to:

cat ~/.ssh/id_dsa.pub | ssh servername “cat >> ~/.ssh/authorized_keys”

You can do this on multiple computers and it should just add to the list, not overwrite. Warning – the .ssh directory must already exist on the remote host or it won’t work…

Setting Default Username for SSH login

Create the file ~/.ssh/config, with the line:

User usernametouse

Using a SSH alias

To set default options for an alias, eg so you can just type ssh aliasname, add the following to ~/.ssh/config:

host aliasname
hostname servername.com
user username

Type man ssh_config for more available options

Update 2013-04-24:

Stopping Timeouts on Virgin Media

For some reason Virgin kills connections that don’t show enough activity, this causes SSH to hang. To fix, add the following to ~/.ssh/config:

Host *
ServerAliveCountMax 600
ServerAliveInterval 10

Using a specific .pem certificate to authenticate

To use a certificate to connect, without installing it as an authorized key on the client, (e.g. for Amazon EC2 in a script):

ssh -i /path/to/certificate.pem servername.com

Posts navigation

← SQL Snippets
Seafile on Raspberry Pi Ubuntu 20.04 →
  • Recent Posts

    • Snapshot backups with Btrfs and Snapper – Raspberry Pi
    • Seafile on Raspberry Pi Ubuntu 20.04
    • SSH Snippets
    • SQL Snippets
    • GNU Screen: Split Screen Terminal
  • Recent Comments

    1. Peet on Seafile on Raspberry Pi Ubuntu 20.04
    2. David Somers on GNU Screen: Split Screen Terminal
    3. Alasdair Macintyre on GNU Screen: Split Screen Terminal
    4. David Somers on GNU Screen: Split Screen Terminal
  • Archives

    • July 2020
    • June 2020
    • January 2012
    • December 2011
    • October 2009
  • Categories

    • Uncategorized
Proudly powered by WordPress Theme: Parament by Automattic.