4

How to Add and Delete SSH Keys

 2 years ago
source link: https://www.vultr.com/docs/how-to-add-and-delete-ssh-keys
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
<?xml encoding="utf-8" ??>

Changing SSH keys on a running server using the Customer Portal will reinstall and wipe all data on the server. You can manually change SSH keys without reinstalling the server by following this Quickstart Guide.

Prerequisites

  • To follow this guide, you must have an SSH key in OpenSSH format. See our guide to create an SSH key.
  • This guide applies to Linux and BSD servers.
  • This guide is suitable for Linux, Mac, or Windows workstations.

Add SSH Key to Vultr Instance

Deploy a new SSH key from a Linux or Mac workstation with ssh-copy-id.

Linux and Mac workstations

The ssh-copy-id utility is pre-installed on most Linux distributions. Mac workstations can install it via Homebrew, MacPorts, or using Curl.

Use the utility to add your public key to the server.

  • Specify the correct public key with the -i [path to public key] parameter.
  • Specify the username and server IP address (or domain name) as shown. For example, the root user at 192.0.2.123:

    $ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
    

    The utility will report some basic information and prompt for your password.

    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/example_user/.ssh/id_rsa.pub"
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
    [email protected]'s password:
    

    Enter your password and the utility installs the key.

    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh '[email protected]'"
    and check to make sure that only the key(s) you wanted were added.
    

Windows workstations

Windows workstations can mimic the ssh-copy-id utility with a one-line PowerShell command. The example shown pipes the the public key through SSH from the current user's profile to the root user's ~/.ssh/authorized_keys.

PS> type $env:USERPROFILE\.ssh\id_rsa.pub | ssh [email protected] "cat >> .ssh/authorized_keys"

Alternate method for any workstation type

  1. SSH to the server.
  2. Edit ~/.ssh/authorized_keys.
  3. Append your public key to the file.
  4. Save and exit.

Delete SSH Key

There are no common automatic methods to delete a public key, you must remove it manually.

  1. SSH to your server.
  2. Edit ~/.ssh/authorized_keys.
  3. Remove the line containing your key.
  4. Save and exit.

Manage SSH Keys via API

The Vultr API offers several endpoints to manage SSH keys.

  • Create a new SSH key for use with future instances. This does not update any running instances.
  • List all SSH keys in your account.
  • Get information about an SSH key.
  • Update an SSH key.
  • Delete an SSH key.

More Information

For more information about managing SSH keys, see our other guides:

Want to contribute?

You could earn up to $600 by adding new articles


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK