Skip to content

Instantly share code, notes, and snippets.

@flackend
Last active December 30, 2015 07:49
Show Gist options
  • Save flackend/7798068 to your computer and use it in GitHub Desktop.
Save flackend/7798068 to your computer and use it in GitHub Desktop.

SSH

You can read about SSH in the man page, man ssh, and the SSH config man page, man ssh_config.

When you have issues, make sure to use the verbose flag, -v.

Password login

If you don't have any public keys in your user's .ssh folder (i.e. /home/jared/.ssh/), you should be able to login without designating any options:

ssh user@192.168.56.100

But if you do have a few keys, SSH may try those first and you might get a Too many authentication failures error. To fix this, set the PubkeyAuthentication option to no:

ssh -o PubkeyAuthentication=no user@192.168.56.100

And/or can set your preferred Authentication method:

ssh -o PreferredAuthentications=password user@192.168.56.100

You can also do this in your SSH config file, /home/jared/.ssh/config.

Passwordless Login

Generate key

Some examples:

ssh-keygen -t rsa -b 4096 -f mykeyfile -C "jared.flack@gmail.com"
ssh-keygen -t rsa -b 4096 -f github.com -C "jared@ethode.com"
ssh-keygen -t rsa -b 4096 -f dev.utees.com -C "jared@ethode.com"

ssh-keygen -t rsa -b 4096 -f centos -C "flack@one-hundred.local"

Flag explanation:

  • -t key type
  • -C comment; used with github to identify user's email
  • -b encryption level; default is 2048, use 4096
  • -f filename

If the key file is named something besides the default id_rsa (if you use the -f flag), then you have to point ssh to the key file:

ssh -i ~/.ssh/mykey user@example.com

You can also just use the ssh config file (~/.ssh/config):

Host example.com
	IdentityFile ~/.ssh/mykey

Set up config file

You can optioally set up a config file to make things a little easier (indentation is optional too):

Host myshortname
	HostName mywebsite.com
	User myusername
	IdentityFile ~/.ssh/mykey

Now you can just ssh myshortname.

Set up the server

Add the contents of the public key you created (so mykeyfile.pub, not mypublickey) to ~/.ssh/authorized_keys. If the file or folder do not exist, create them.

If you need to install Git, see Git.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment