Skip to content

Instantly share code, notes, and snippets.

@ijash
Last active January 1, 2020 14:48
Show Gist options
  • Save ijash/536af48bd1fd70fc47826a989d8f5263 to your computer and use it in GitHub Desktop.
Save ijash/536af48bd1fd70fc47826a989d8f5263 to your computer and use it in GitHub Desktop.

Passwordless ssh or copy public key

Key based authentication in SSH is called public key authentication. The purpose of ssh-copy-id is to make setting up public key authentication easier.

Assuming:

  • OpenSSH in both client and server is installed accordingly.
  • Both computer/host using popular GNU/linux distribution which OpenSSH enabled by default.
  • C is known as Client or user's computer/host.
  • R is known as Remote or remote server/computer/host.

Open the terminal and follow this process:

  1. C: Generate public key:
    ssh-keygen -t rsa
  2. R: If not exist, make a .ssh folder on host's home folder:
    mkdir -p .ssh
  3. C: Use either one of this:
    cat .ssh/id_rsa.pub  |ssh [email protected] 'cat>> .ssh/authorized_keys'
    or (recommended)
    ssh-copy-id [email protected]
  4. C: Now, login to remote computer, it should be not asking password now:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment