Linux public key file

How do I access my SSH public key?

I’ve just generated my RSA key pair, and I wanted to add that key to GitHub. I tried cd id_rsa.pub and id_rsa.pub , but no luck. How can I access my SSH public key?

Yes, the other seems to be better positioned (based on the wording, etc.), it has more views and votes within shorter period of time which indicates it’s much more popular. See: Should I vote to close a duplicate question, even though it’s much newer, and has more up to date answers? Once duplicate, both answers could be merged into one.

24 Answers 24

cat ~/.ssh/id_rsa.pub or cat ~/.ssh/id_dsa.pub

You can list all the public keys you have by doing:

Even though I see the file in the place it’s referring to (C:/Users/Me/.ssh/.id_rsa.pub), these commands are producing an error: No such file or directory. I’m doing this from Git Bash, MyPC ~/.ssh

@sscirrus: In windows, you can use type command. Or just open the .pub file in notepad and paste it to github.

Copy the key to your clipboard.

Warning: it’s important to copy the key exactly without adding newlines or whitespace. Thankfully the pbcopy command makes it easy to perform this setup perfectly.

and paste it wherever you need.

sudo apt-get install -y xclip followed by alias pbcopy=»xclip -sel clip» and then pbcopy < ~/.ssh/id_rsa.pub OR simply xclip -selection clipboard < ~/.ssh/id_rsa.pub

You may try to run the following command to show your RSA fingerprint:

ssh-agent sh -c 'ssh-add; ssh-add -l' 
ssh-agent sh -c 'ssh-add; ssh-add -L' 

If you’ve the message: ‘The agent has no identities.’, then you’ve to generate your RSA key by ssh-keygen first.

Using ssh-add -L is by far the better option as not every SSH key is an RSA key sitting in the ~/.ssh folder. I much prefer to use my PGP key for authentication and so I do not have a ~/.ssh/id_rsa.pub file at all.

If you’re on Windows use the following, select all, and copy from a Notepad window:

Mac, Ubuntu, Linux compatible machines, use this command to print public key, then copy it:

Here’s how I found mine on OS X:

If that doesn’t work, do an ls and see what files are in there with a .pub extension.

On terminal cat ~/.ssh/id_rsa.pub

explanation

  1. cat is a standard Unix utility that reads files and prints output
  2. ~ Is your Home User path
  3. /.ssh — your hidden directory contains all your ssh certificates
  4. id_rsa.pub OR id_dsa.pub are RSA public keys, (the private key located on the client machine). the primary key for example can be used to enable cloning project from remote repository securely to your client end point.
Читайте также:  Capt printer driver linux

After you generate your SSH key you can do:

which will copy your ssh key into your clipboard.

If you’re using windows, the command is:

type %userprofile%\.ssh\id_rsa.pub

it should print the key (if you have one). You should copy the entire result. If none is present, then do:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

If you are using Windows PowerShell, the easiest way is to:

That will copy the key to your clipboard for easy pasting.

So, in my instance, I use ed25519 since RSA is now fairly hackable:

cat ~/.ssh/id_ed25519.pub | clip 

Because I find myself doing this a lot, I created a function and set a simple alias I could remember in my PowerShell profile (learn more about PowerShell profiles here. Just add this to your Microsoft.PowerShell_profile.ps1 :

function Copy-SSHKey < Get-Content ~/.ssh/id_ed25519.pub | clip >Set_Alias -Name sshkey -Value Copy-SSHKey 

Then, in a PowerShell console, run . $profile to load the functions. Then from now on all you will need to do is run sshkey , and then paste the key into wherever you need via the clipboard.

If you only have your private key available, you can generate the public key from it:

ssh-keygen -y -f path/to/private_key 

The following command will save the SSH key on the clipboard. You only need to paste at the desired location.

Open your id_dsa.pub or some_name.pub file with gedit and copy-paste the contents!

When i do so, its opening a blank file. Its not showing any text in it. But when i browse through file manager, i’m able to see the text.

# sudo su # cd /home/user/.ssh .ssh# gedit id_rsa.pub 

Then copy the entire file without any spaces. Click your icon at the top right of the GitHub page, go to settings, and add ssh.

Paste the copy into the space. It may prompt for your GitHub password. Enter it. Save.

 ssh-keygen -o -t rsa -b 4096 -C "email@example.com" 

And After that Just Copy And Paste

It can be found on this path (default path):

john is your Mac username.

It is very simple. After you generated ssh key on your computer, you can access your public ssh key by following command

You should see output similar to the following:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyVGaw1PuEl98f4/7Kq3O9ZIvDw2OFOSXAFVqilSFNkHlefm1iMtPeqsIBp2t9cbGUf55xNDULz/bD/4BCV43yZ5lh0cUYuXALg9NI29ui7PEGReXjSpNwUD6ceN/78YOK41KAcecq+SS0bJ4b4amKZIJG3JWmDKljtv1dmSBCrTmEAQaOorxqGGBYmZS7NQumRe4lav5r6wOs8OACMANE1ejkeZsGFzJFNqvr5DuHdDL5FAudW23me3BDmrM9ifUzzjl1Jwku3bnRaCcjaxH8oTumt1a00mWci/1qUlaVFft085yvVq7KZbF2OPPbl+erDW91+EZ2FgEi+v1/CSJ5 your_username@hostname 

Also note that the public key begins with ssh-rsa and ends with your_username@hostname.

Источник

How to Add SSH Public Key to Server

Public key authentication allows you to access a server via SSH without password. Here are two methods to copy the public ssh key to the server.

Public key authentication allows you to access a server via SSH without password. Here are two methods to copy the public ssh key to the server.

I believe you understand the basic SSH concept. Your Linux server has ssh enabled. You have generated ssh keys on your personal computer. Now you want to upload your public key to the authorized keys of the server so that you can access it without typing your account password all the time.

Читайте также:  Linux debian или mint

This quick tutorial shows you two methods to add a public SSH key to the server.

Requirements

Before you see that, let’s be clear about what you should already have:

  • Your destination server should have ssh enabled
  • You should have generated public and private ssh keys (just use the command ssh-keygen -t rsa)
  • You should have a user account and password on the server. Even root account will do.
  • You should know the IP address of the server

Now that you have made sure of the above four requirements, let’s see how to use public key authentication.

The authentication is per user base so the public key goes in the intended user’s home.

SSH Public Key Authentication

Method 1: Automatically copy the ssh key to server

The first method is where the end user copies its personal computer’s public key to the list of the authorized keys on the remote server.

Here, I assume that you were able to log in to the remote server using ssh [email protected]_of_server. It asks for your account’s password and you enter the server.

If you add your public key to the server, you should be able to log in without typing the password all the time.

OpenSSH provides a handy tool call called ssh-copy-id for copying ssh public keys to remote systems. It even creates required directories and files.

As I mentioned earlier, you should know the username and password to the server you want to access via public key authentication.

When prompted, enter the password for your user account at the remote server. Your public key should be copied at the appropriate folder on the remote server automatically.

I have used ~/.ssh/id_rsa.pub because that is the default location for the public ssh key. If you have it at some other location, you should use that in the above command.

Method 2: Manually copy the public ssh key to the server

The first method had the action on the user side. Let’s say that you are the sysadmin and your server doesn’t allow SSH login via password. The only way to access the server is using SSH public key authentication.

In such a case, you can ask the end user to provide her/his public key. Now what you can do is to create .ssh/authorized_keys directory and then copy the public key here.

Step 1: Get the public key

Ask the end user to provide the public key by typing the following command:

It will show a long random string starting with ssh-rsa:

You can get this text via email or messaging tools. Normally, it shouldn’t be a problem.

Step 2: Create ssh directory in the user’s home directory (as a sysadmin)

Keep in mind that you have to create these new directories and files in the end user’s home directory, not your own (root/sysadmin).

mkdir -p /home/user_name/.ssh && touch /home/user_name/.ssh/authorized_keys

Now open this /home/user_name/.ssh/authorized_keys file with a text editor like Vim and add the public key of the user here:

vim /home/user_name/.ssh/authorized_keys

Save and close the file. It’s almost ready.

Читайте также:  Stream what you hear linux

Step 3: Set appropriate permission to the file

Having appropriate file permission on the ssh file is very important otherwise you’ll see errors like Permission denied (publickey).

First, make sure to set the correct file permissions:

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

You created those file with either root or your own admin accounts for some other user. You need to change the ownership to the user:

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

Now that it’s done, you can ask the end user to log in to the server.

Do let me know if you face any issues or if you have any suggestion on this topic.

Источник

4.3 Git on the Server — Generating Your SSH Public Key

Many Git servers authenticate using SSH public keys. In order to provide a public key, each user in your system must generate one if they don’t already have one. This process is similar across all operating systems. First, you should check to make sure you don’t already have a key. By default, a user’s SSH keys are stored in that user’s ~/.ssh directory. You can easily check to see if you have a key already by going to that directory and listing the contents:

$ cd ~/.ssh $ ls authorized_keys2 id_dsa known_hosts config id_dsa.pub

You’re looking for a pair of files named something like id_dsa or id_rsa and a matching file with a .pub extension. The .pub file is your public key, and the other file is the corresponding private key. If you don’t have these files (or you don’t even have a .ssh directory), you can create them by running a program called ssh-keygen , which is provided with the SSH package on Linux/macOS systems and comes with Git for Windows:

$ ssh-keygen -o Generating public/private rsa key pair. Enter file in which to save the key (/home/schacon/.ssh/id_rsa): Created directory '/home/schacon/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/schacon/.ssh/id_rsa. Your public key has been saved in /home/schacon/.ssh/id_rsa.pub. The key fingerprint is: d0:82:24:8e:d7:f1:bb:9b:33:53:96:93:49:da:9b:e3 schacon@mylaptop.local

First it confirms where you want to save the key ( .ssh/id_rsa ), and then it asks twice for a passphrase, which you can leave empty if you don’t want to type a password when you use the key. However, if you do use a password, make sure to add the -o option; it saves the private key in a format that is more resistant to brute-force password cracking than is the default format. You can also use the ssh-agent tool to prevent having to enter the password each time.

Now, each user that does this has to send their public key to you or whoever is administrating the Git server (assuming you’re using an SSH server setup that requires public keys). All they have to do is copy the contents of the .pub file and email it. The public keys look something like this:

$ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSU GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3 Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx NrRFi9wrf+M7Q== schacon@mylaptop.local

Источник

Оцените статью
Adblock
detector