LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-21-2023, 03:06 AM   #1
banderas20
Member
 
Registered: Aug 2018
Posts: 138

Rep: Reputation: Disabled
Question Security doubt about ssh-copy-id


Hi!

I have been using SSH for a long time, and I do know the purpose of ssh-copy-id command.

If I copy the pubfile contents and paste it into the authorised_keys file on the target server, that's OK, because I already have access to the target server, and there are not security concerns.

However, I have a silly doubt regarding how ssh-copy-id command works.

Whenever we issue ssh-copy-id -i <pubfile> user@host, we are adding the pubfile contents to authorised_keys file of the ./ssh directory of "user" on "host" machine. But we don't necessary have access to that server yet.

Why can anyone issue that command from anywhere without being asked anything? I mean... anyone could add an arbitrary public key and gain access to any server. Who or which mechanism controls that?

Sorry if that's an obvious question, but I can't find the clue.

Thanks!
 
Old 07-21-2023, 03:38 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,026

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
if you don't have access to the server you won't be able to add pubfile to authorised_keys. That is that simple.
 
Old 07-21-2023, 04:26 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,781

Rep: Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935Reputation: 5935
In other words to copy the keys with ssh-copy-id you still need to be able to login to that server with a valid username and password. It is basically a script that uses the ssh command.

Last edited by michaelk; 07-21-2023 at 04:34 AM.
 
Old 07-21-2023, 06:15 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,346
Blog Entries: 3

Rep: Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756
Quote:
Originally Posted by banderas20 View Post
Sorry if that's an obvious question, but I can't find the clue.
In addition to the above comments, you can look at the contents of ssh-copy-id itself, it's just a simple shell script.

You can copy the keys by hand too, either via password or out of band though out of band is a lot more difficult and time consuming.
 
Old 07-21-2023, 06:35 AM   #5
banderas20
Member
 
Registered: Aug 2018
Posts: 138

Original Poster
Rep: Reputation: Disabled
OK. I'm beginning to get it.

So, which user should I use to issue ssh-copy-id?
So far I'm trying it with a sudo user which exists on my local machine, but not in the remote server.

Should my local user exist on the remote one?

Thanks!
 
Old 07-21-2023, 06:42 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,026

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
There are two users involved, the local user which has an id and the remotes user. You need to use the local user to copy that id to the remote host using that remote user.
 
Old 07-21-2023, 08:09 AM   #7
banderas20
Member
 
Registered: Aug 2018
Posts: 138

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
There are two users involved, the local user which has an id and the remotes user. You need to use the local user to copy that id to the remote host using that remote user.

OK. Here's what I do:

LOCAL:
Code:
/home/localuser/.ssh/ssh-keygen (keypair named "test2")
/home/localuser/.ssh/ssh-copy-id -i test2.pub test@192.168.1.138 (test user already exists in 192.168.1.138)

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "test.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
Received disconnect from 192.168.1.138 port 22:2: Too many authentication failures
Disconnected from 192.168.1.138 port 22
EDIT: solved

PasswordAuthentication yes
MaxAuthTries 100

I got rid of the message, was prompted for the password and now able to add the pubkey

Thanks everyone!

Last edited by banderas20; 07-21-2023 at 08:51 AM. Reason: solved
 
  


Reply

Tags
ssh, ssh keys, ssh-keygen



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh-copy-id: ERROR: failed to create required temporary directory under ~/.ssh Cannondale Linux - Newbie 4 03-07-2023 05:55 AM
[SOLVED] Copying your Public SSH Key to a Server with SSH-Copy-ID when the server is already set with 'PubkeyAuthentication yes' Liniub Linux - Newbie 4 05-02-2020 12:15 PM
Want to change how pasted files are named "(copy)," "(another copy)," "(3rd copy)" L a r r y Linux - Desktop 3 08-24-2013 03:39 PM
Doubt in Copy-on-Write (CoW) in LVM Snapshots vikas027 Linux - Server 1 05-24-2012 08:04 AM
[SOLVED] Small doubt for using wget cia SSH!!! rockf1bull Red Hat 2 10-11-2011 12:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration