Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
ssh Permission denied (publickey).
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 39

PostPosted: Fri Dec 13, 2024 2:22 pm    Post subject: ssh Permission denied (publickey). Reply with quote

in a while ssh doesn' t works more in the directory .ssh there isn' t certificate and i cant create
Code:

m@localhost ~ $ ls .ssh/
known_hosts
m@localhost ~ $ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/m/.ssh/id_rsa): ~/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Saving key "~/.ssh/id_rsa" failed: No such file or directory
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22817

PostPosted: Fri Dec 13, 2024 2:28 pm    Post subject: Reply with quote

Your subject line is about the server refusing to let you in due to failed public key authentication. Your body is about failure to create an unusually named key file. Does your home directory contain a directory named ~, and within that, a directory named .ssh? What is the output of namei -l '~/.ssh/id_rsa'? Note the single quotes, since you need to inhibit tilde expansion to match what ssh seems to do.
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1330
Location: Richmond Hill, Canada

PostPosted: Fri Dec 13, 2024 2:31 pm    Post subject: Reply with quote

'~' as home directory is program specific. Most shell support this. However I think ssh-keygen in you case does not support. so it take the character '~' literally as a directory name.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 39

PostPosted: Fri Dec 13, 2024 2:41 pm    Post subject: Reply with quote

Code:

m@localhost ~ $ namei -l '~/.ssh/id_rsa'
f: ~/.ssh/id_rsa
              ~ - No such file or directory
m@localhost ~ $ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/m/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/m/.ssh/id_rsa
Your public key has been saved in /home/m/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:RwPnEPcJXXtHU08XPZWxTulcKdKz/gOyV/x8gdie+WA m@localhost
The key's randomart image is:
+---[RSA 4096]----+
|        +.+. ..+&|
|         * oo. *O|
|          +.o+.=*|
|         . .. O.o|
|        S . o.o+ |
|         . o.+ + |
|            +E=.o|
|           ..=o.+|
|            . .oo|
+----[SHA256]-----+
m@localhost ~ $ ls .ssh
id_rsa  id_rsa.pub  known_hosts


now create the certificate and now?
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1330
Location: Richmond Hill, Canada

PostPosted: Fri Dec 13, 2024 3:03 pm    Post subject: Reply with quote

Marcofras wrote:
Code:

m@localhost ~ $ namei -l '~/.ssh/id_rsa'
f: ~/.ssh/id_rsa
              ~ - No such file or directory
m@localhost ~ $ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/m/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/m/.ssh/id_rsa
Your public key has been saved in /home/m/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:RwPnEPcJXXtHU08XPZWxTulcKdKz/gOyV/x8gdie+WA m@localhost
The key's randomart image is:
+---[RSA 4096]----+
|        +.+. ..+&|
|         * oo. *O|
|          +.o+.=*|
|         . .. O.o|
|        S . o.o+ |
|         . o.+ + |
|            +E=.o|
|           ..=o.+|
|            . .oo|
+----[SHA256]-----+
m@localhost ~ $ ls .ssh
id_rsa  id_rsa.pub  known_hosts


now create the certificate and now?
Is there a question?
Please note the command 'ssh-keygen -t rsa -b 4096' does NOT create "certificate" it create a "private key" which is "rsa" type of 4096 in length.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 39

PostPosted: Fri Dec 13, 2024 3:06 pm    Post subject: Reply with quote

i dont understand what i have to do now?
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1330
Location: Richmond Hill, Canada

PostPosted: Fri Dec 13, 2024 3:10 pm    Post subject: Reply with quote

Marcofras wrote:
i dont understand what i have to do now?
In theory there is nothing to do. I think you need to explain what is that you have in mind in term of running the ssh-keygen command.

You can consider copy the public key 'id_rsa.pub' to where you wish to ssh to.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 39

PostPosted: Fri Dec 13, 2024 3:15 pm    Post subject: Reply with quote

i cant connect to the server and i have this message
Code:

m@localhost ~ $ ssh root@212.227.87.63
root@212.227.87.63: Permission denied (publickey).

this is the main problem and i attempt to solve following the guides i found on google but it doesnt works.
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1330
Location: Richmond Hill, Canada

PostPosted: Fri Dec 13, 2024 3:23 pm    Post subject: Reply with quote

Marcofras wrote:
i cant connect to the server and i have this message
Code:

m@localhost ~ $ ssh root@212.227.87.63
root@212.227.87.63: Permission denied (publickey).

this is the main problem and i attempt to solve following the guides i found on google but it doesnt works.


The destination 212.227.87.63 is requesting use publickey authentication method. it will not accept any other way.

So you will need to find a way to copy your public key 'id_rsa.pub' into 212.227.87.64:<root homedir>/.ssh/known_hosts.

Are you sure the destination 212.227.87.63 allow 'root' to login?

P.S. when I say 'copy public key id_rsa.pub' I don't mean the file. I mean the content of the file.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 39

PostPosted: Fri Dec 13, 2024 3:37 pm    Post subject: Reply with quote

i access the server with remote console provided and in the directory ssh i see only authorized_keys do i have to create the file known_hosts?
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1951

PostPosted: Fri Dec 13, 2024 3:40 pm    Post subject: Reply with quote

Marcofras wrote:
i access the server with remote console provided and in the directory ssh i see only authorized_keys do i have to create the file known_hosts?

Append to authorized_keys (not overwrite) on a new line. You do not need known_hosts.
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1330
Location: Richmond Hill, Canada

PostPosted: Fri Dec 13, 2024 3:41 pm    Post subject: Reply with quote

Marcofras wrote:
i access the server with remote console provided and in the directory ssh i see only authorized_keys do i have to create the file known_hosts?
yes. and the file need to be own by root have permission of 0600.
Back to top
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1330
Location: Richmond Hill, Canada

PostPosted: Fri Dec 13, 2024 3:42 pm    Post subject: Reply with quote

grknight, is correct, I got the file name mixup. it is 'authorized_keys'
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22817

PostPosted: Fri Dec 13, 2024 3:58 pm    Post subject: Reply with quote

pingtoo wrote:
yes. and the file need to be own by root have permission of 0600.
This ownership comment is correct in this specific case, but in the general case, the authorized_keys file needs to be owned by the user who is granting access. OP specifically wants root access in this case, so saying own by root is fine here. However, if the OP were authorizing login as some non-root user, such as bob, then the file needs to be owned by bob and located at ~bob/.ssh/authorized_keys.
Back to top
View user's profile Send private message
Marcofras
n00b
n00b


Joined: 29 May 2023
Posts: 39

PostPosted: Fri Dec 13, 2024 4:05 pm    Post subject: Reply with quote

the content of .ssh/id_rsa.pub, ok i will try
Back to top
View user's profile Send private message
sMueggli
Guru
Guru


Joined: 03 Sep 2022
Posts: 508

PostPosted: Sat Dec 14, 2024 9:48 am    Post subject: Reply with quote

pingtoo wrote:
Please note the command 'ssh-keygen -t rsa -b 4096' does NOT create "certificate" it create a "private key" which is "rsa" type of 4096 in length.


The command creates the private key (never share this key!) and the corresponding public key (which can safely be shared).

I would not recommend to allow SSH access to root. If you do, please create a password-protected private key.

To setup SSH I would allow password-based access to a normal user and then use the command "ssh-copy-id" to transfer the public key to the remote user on the remote computer. When SSH access with the key works, disable passwords as authentication method.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum