Skip to content
Technology News Information & Jobs

Technology News Information & Jobs

Ubuntu Tutorials, Ubuntu How To , Linux Tips, Tech Jobs

  • Work with US
  • Search Jobs
  • Post a Job
  • Contact Us
  • Ubuntu
    • Ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Themes
  • Linux
  • Laptops
  • Tutorials
  • Job Dashboard
  • Toggle search form
How To Add SSH Public Key To Server

How To Add SSH Public Key To Server

Posted on April 5, 2022February 23, 2023 By admin No Comments on How To Add SSH Public Key To Server

Methods to add ssh public key to the server

In this tutorial, we will show you the methods to copy the public ssh key to the server. The public-key authentication method requires you to copy your public SSH key to the server’s authorized_keys file. You might be wondering why we need to add the SSH key to the server as the reason to add ssh key to the server is to allow you to access a server via SSH without a password. Here are two methods to copy the public ssh key to the server.

How To Add SSH Public Key To Server

Let’s go through the process of adding the ssh key to the server.

Copy ssh public key to remote server using ssh-copy-id:

In this very first method, we will copy the ssh public key to the server using ssh-copy-id tool. In this process, we will copy the personal computer’s public key to the list of the authorized keys on the remote server. The authorized_keys file is in the ~/.ssh/

ssh-copy-id -i ~/.ssh/id_rsa.pub validusername@IP_ADDRESS_OF_THE_SERVER

When prompted, enter the password for your user account at the remote server. Your public key should be copied to the remote server.
~/.ssh/id_rsa.pub  is the default location for the public ssh key. If you want to use another public key rather than the one in the default location, use the -i option.

READ More Relevant Stuff:  Useful Best GNOME Desktop Extensions Updated

Manually copy the public ssh key to the server

In another method, we can manually copy the ssh key to the server.  This method is useful when your server doesn’t allow you ssh login via password. In this process, you need to ask the end-user to provide their pubic key at first.

cat ~/.ssh/id_rsa.pub

Manually append your public key to the remote ssh server’s key to the authorized_keys file. For example, copy the content of your ~/.ssh/id_rsa.pub to the server’s ~/.ssh/authorized_keys file.

Using the following command combination

cat ~/.ssh/id_rsa.pub | ssh user@remote-host 'cat >> ~/.ssh/authorized_keys'

Now, create new directories and files in the end user’s home directory so that you can add the public key of the end user that you have asked for in the previous step.

Now add the public key of the user in /home/user_name/.ssh/authorized_keys file

vim /home/username/.ssh/authorized_keys

Save and close the file.

Now, if your end-users tried to connect to a remote server then they might come across a permission denied error or something like this “r “sign_and_send_pubkey: signing failed: agent refused operation Permission denied (publickey)”.

One of the reasons for this is due to file permission on ssh file.  Make sure to set the correct file permissions:

chmod 700 /home/username/.ssh && chmod 600 /home/username/.ssh/authorized_keys

Change the ownership to the user:

chown -R username:username /home/username/.ssh

Now your end-user can log in to the server without any issue

How To Ubuntu Tags:ssh

Post navigation

Previous Post: Epic Programming Jokes Only Programmers Will Get
Next Post: Fix sudo apt-get install openssh-server not working error : Enable SSH Server on Ubuntu

Related Posts

10+ Basic Cat Command Examples in Linux [2023] 10+ Basic Cat Command Examples in Linux [2023] How To Ubuntu
Rsync Command In Linux With Examples [Updated] Rsync Command In Linux With Examples [Updated] How To Ubuntu
How To Fix “Sub-process /usr/bin/dpkg returned an error code (1)” Error In Ubuntu How To Fix “Sub-process /usr/bin/dpkg returned an error code (1)” Error In Ubuntu Fix
Update the NVIDIA Drivers on Ubuntu 22.04 LTS [How To] How To Update the NVIDIA Drivers on Ubuntu 22.04 LTS How To Ubuntu
How To Upgrade Linux Kernel Linux Kernel 5.8 Reaches End of Life, Better Upgrade To Latest Version How To Ubuntu
How To Install Composer On Ubuntu 20.04 LTS How To Install Composer On Ubuntu 20.04 LTS How To Ubuntu

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Enable Hibernate in Ubuntu 22.04 LTS May 20, 2024
  • Popular Ubuntu Games: Top 5 Games To Play March 17, 2024
  • WordPress | Your site doesn’t include support for the “generateblocks/container” block GenerateBlocks Plugin February 11, 2024
  • Ubuntu Autoremove Command Debian Autoremove Command February 10, 2024
  • How To Mount Windows 11 Shares on Debian Linux December 7, 2023
  • Anonymous Browsing 101: A Deep Dive Into Residential Proxies November 20, 2023
  • How To Correctly Install Uninstall Linux Ubuntu Nvidia Drivers Fast October 31, 2023
  • Ethical Web Design: The Dos and Don’ts October 28, 2023
  • Understanding the Role of Security Operations Center October 25, 2023
  • The Positive Effects of AI Tools and Online Services on Students Successful Essay-Writing Skills October 3, 2023
  • Linux Wget Examples September 27, 2023

Categories

  • Android
  • Apple
  • Blogs
  • Debian
  • Fix
  • Gadgets
  • Game
  • Google
  • How To Ubuntu
  • Internet
  • Laptops
  • Linux
  • Linux Commands
  • Linux Game
  • Linux Mint
  • News
  • Operating Systems
  • Security
  • Technology
  • Themes
  • Tools
  • Tutorials
  • Ubuntu
  • ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Windows 11
  • Wordpress
  • Search Jobs
  • Post a Job
  • Job Dashboard
  • Contact Us
  • About US
  • Cookie Policy
  • Terms and Conditions
  • Privacy Policy
  • Sitemap
  • Write For US

Tags

android apps centos ChatGPT command Commands Debian deepin Desktop docker Fedora fix game games Gaming gnome google kernel linux linux commands linux kernel Linux laptops Linux Mint Linux themes minecraft NVIDIA Python Raspberry Pi sysadmin themes ubuntu ubuntu 18.04 Ubuntu 18.04 LTS Ubuntu 20.04 ubuntu 20.04 lts Ubuntu 22.04 LTS Ubuntu games Ubuntu kernel ubuntu themes ubuntu tutorial VirtualBox Windows Windows 11 Wine WSL
itsubuntu.com is an Equal Opportunity Employer. For Advertisement, Jobs, Guest posts, and any other thoughts, email us at [email protected]
  • SERVICE WRITER – FLOAT

    • Sauk City, WI
    • McFarlane's
    • Full Time
  • User Experience Writer

    • Orlando, FL
    • Radiant Digital
    • Full Time
  • Customs Entry Writer

    • Long Beach, CA
    • Coda Search│Staffing
    • Full Time
  • Technical Writer

    • Carlsbad, NM
    • Airswift
    • Full Time
  • Technical Writer

    • Palo Alto, CA
    • DeWinter Group
    • Full Time
  • Technical Writer

    • Hanover, MD
    • TAD PGS, Inc.
    • Full Time
  • Senior Data Scientist

    • San Francisco, CA (Remote)
    • Patreon
    • Full Time
  • Technical Writer

    • Michigan
    • US Tech Solutions
    • Full Time

Copyright © 2025 Technology News Information & Jobs.

Powered by PressBook Grid Blogs theme