dissabte, 3 de febrer del 2018

ssh keys


From my laptop I will create the keys and I will expose this key to the server I want to connect using keys. Additionally we get rid of passwords , even for my user as sudo user.

jordi@LAPTOP-ELFAQNCG MINGW64 ~/.ssh
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/jordi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/jordi/.ssh/id_rsa.
Your public key has been saved in /c/Users/jordi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ljvEge2a/MwKp8OK73ai27v7zRFiPyPmMxJCpw0nJLU jordi@LAPTOP-ELFAQNCG
The key's randomart image is:
+---[RSA 2048]----+
| ..              |
|.. .   o         |
|o E   . o        |
| + o   o o       |
|. B o . S        |
|...o + * .       |
| . o+ X o        |
| o+o*B B .       |
|+*OX+++.+        |
+----[SHA256]-----+

jordi@LAPTOP-ELFAQNCG MINGW64 ~/.ssh
$ ssh-copy-id jordi@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/c/Users/jordi/.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
no such identity: /c/Users/jordi/.ssh/keys/id_rsa.pub: No such file or directory
jordi@localhost's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'jordi@localhost'"
and check to make sure that only the key(s) you wanted were added

jordi@LAPTOP-ELFAQNCG MINGW64 ~/.ssh
$ cat config
Host localhost
 Hostname localhost
 IdentityFile ~/.ssh/id_rsa
.

jordi@LAPTOP-ELFAQNCG MINGW64 ~/.ssh
$ ssh localhost
Last login: Sat Feb  3 17:27:47 2018 from gateway
[jordi@localhost ~]$

At centos to avoid password for instance to avoid pas to do sudo

/etc/ssh/sshd_config
PasswordAuthentication no

addl to the bototn
 sudo visudo
jordi ALL=(ALL) NOPASSWD: ALL

Cap comentari:

Publica un comentari a l'entrada