the command scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys
is going to copy your public keyThink of ssh and overwrite the authorized_keys found in /home/your_usernamescp as two separate programs:
on your client workstation, you are your_username. in ~/.ssh/authorized_keys there is a file id_rsa.pub
on your serverremote workstation, you are your_username in ~/.ssh there is a file authorized_keys that the contents of id_rsa.pub is also.
I assumewhen you want to add or append your keyssh to this file, so on the server you can either opentype:
ssh -i ~/id_rsa.pub your_username@remote_server
The -i
is a flag that takes a filename as an argument; it means identity. You present the key found in the file to edit and paste the contentsserver, or you could do 'echo [the contentsinstead of your public key go here] >>a password.
If no identity is presented by ssh, it defaults to presenting ~/.ssh/authorized_keysid_rsa.pub
Ifwhen you are attempting to do it as a different user than your_usernamenot need to login, but wish to copy a file to the remote server you are correctly deniedcan use scp and type:
scp -i ~/id_rsa.pub your_username@remote_server:/path/to/directory/
The -i
is a flag that takes a filename as an argument; it means identity. You present the key found in the file to the server, instead of a password. There is only writable by your_usernameno default identity presented, if none is specified.
If you can also try scp'ing to 192.0.2.0type the command you presented:/
scp ~/.ssh/id_rsa.pub <username>@<host>:~/.ssh/authorized_keys
You are saying copy the file ~/.ssh/id_rsa.pub
to the remote server and overwrite ~/tmp.ssh/ and then interacting with it there onceauthorized_keys. you sshare not presenting a key to the server, unless you specify a file with -i
.
But if, as you've stated you're already successful logging in with the key, i'm not clear whyWhen you would needconnect to still adda remote server you must type your publicpassword, or present an ssh key toeach time.
On the remote server make sure the contents of the authorized_keys file matches id_rsa.pub on your client machine. set its permissions to 600
But if you can then successfully login via ssh using a key, you should be able to the hostcopy files as any user, andyour_username provided you want ~/have permissions on the remote directory.ssh/id_rsa
try whatever scp command you are running again, but include -i ~/.ssh/id_rsa.pub
each time.
If you truly are trying to copy id_rsa.pub to be included in your_username's keys file, keep it easy on yourself and do thisto the remote authorized_keys. the command to run is:
locally: catscp -i ~/.ssh/id_rsa.pub #copy the resulting text ssh 192.0.2.0 sudo vi /path ~/to.ssh/your_username's_home_dirid_rsa.pub @:~/.ssh/authorized_keys remotely: #paste public key contents here ssh [email protected]