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

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:  How To Update the NVIDIA Drivers on Ubuntu 22.04 LTS

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+ Bash: If, Else If, Else Examples 10+ Bash: If, Else If, Else Examples How To Ubuntu
How to Fix “Connection refused by port 22” on Ubuntu How to Fix “Connection Refused By Port 22” On Ubuntu 22.04 LTS How To Ubuntu
How to Install Java On Ubuntu 22.04 LTS How to Install Java On Ubuntu 22.04 LTS How To Ubuntu
How To Access Linux Files From Windows 11 How To Access Linux Files From Windows 11 [2023] How To Ubuntu
Best Tools To Create Your Own Custom Linux OS In 2023 Best Tools To Create Your Own Custom Linux OS In 2023 Linux
Useful Best GNOME Desktop Extensions In 2021 Useful Best GNOME Desktop Extensions Updated How To Ubuntu

Recent Posts

  • New Job Search October 10, 2025
  • 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

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]
  • Automotive Service Writer

    • Orlando, FL
    • Midas BONINI
    • Full Time
  • Experienced Hyundai Service Writer

    • Vernon, CT
    • Key Hyundai of Manchester
    • Full Time
  • Service Writer (Service Sales)

    • Modesto, CA
    • Pacific Material Handling Solutions Inc
    • Full Time
  • Service Writer

    • Decatur, AL
    • Skyworks LLC
    • Full Time
  • Data Engineering Consultant

    • Phoenix, AZ (Remote)
    • Plex Consulting, LLC
    • Full Time
  • Service Writer – Heavy Diesel Mobile Repair

    • Oklahoma City, OK
    • Turbo Diesel of Oklahoma
    • Full Time
  • Personal Injury Demand Writer – Burbank

    • Burbank, CA
    • Direct Counsel
    • Full Time
  • Service Writer Powersports Service Department

    • Springfield, MO
    • Pitbull Powersports
    • Full Time

Copyright © 2025 Technology News Information & Jobs.

Powered by PressBook Grid Blogs theme