Skip to main content
added 776 characters in body
Source Link

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]

the command scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys is going to copy your public key and overwrite the authorized_keys found in /home/your_username/.ssh/authorized_keys file on your server.

I assume you want to add or append your key to this file, so on the server you can either open the file to edit and paste the contents, or you could do 'echo [the contents of your public key go here] >> ~/.ssh/authorized_keys

If you are attempting to do it as a different user than your_username, you are correctly denied as the file is only writable by your_username.

you can also try scp'ing to 192.0.2.0://tmp/ and then interacting with it there once you ssh.

But if, as you've stated you're already successful logging in with the key, i'm not clear why you would need to still add your public key to the authorized_keys file.

But if you can ssh to the host as any user, and you want ~/.ssh/id_rsa.pub to be included in your_username's keys file, keep it easy on yourself and do this:

locally: cat ~/.ssh/id_rsa.pub #copy the resulting text ssh 192.0.2.0 sudo vi /path/to/your_username's_home_dir/.ssh/authorized_keys remotely: #paste public key contents here ssh [email protected]

Think of ssh and scp as two separate programs:

on your client workstation, you are your_username. in ~/.ssh there is a file id_rsa.pub

on your remote workstation, you are your_username in ~/.ssh there is a file authorized_keys that the contents of id_rsa.pub is also.

when you want to ssh to the server you type:

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 the server, instead of a password. If no identity is presented by ssh, it defaults to presenting ~/.ssh/id_rsa.pub

when you do not need to login, but wish to copy a file to the remote server you can 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 no default identity presented, if none is specified.

If you type 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 ~/.ssh/authorized_keys. you are not presenting a key to the server, unless you specify a file with -i.

When you connect to a remote server you must type your password, or present an ssh key each 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

if you can then successfully login via ssh using a key, you should be able to copy files as your_username provided you have permissions on the remote directory.

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 the remote authorized_keys. the command to run is:

scp -i ~/.ssh/id_rsa.pub ~/.ssh/id_rsa.pub @:~/.ssh/authorized_keys

Source Link

the command scp ~/.ssh/id_rsa.pub [email protected]:~/.ssh/authorized_keys is going to copy your public key and overwrite the authorized_keys found in /home/your_username/.ssh/authorized_keys file on your server.

I assume you want to add or append your key to this file, so on the server you can either open the file to edit and paste the contents, or you could do 'echo [the contents of your public key go here] >> ~/.ssh/authorized_keys

If you are attempting to do it as a different user than your_username, you are correctly denied as the file is only writable by your_username.

you can also try scp'ing to 192.0.2.0://tmp/ and then interacting with it there once you ssh.

But if, as you've stated you're already successful logging in with the key, i'm not clear why you would need to still add your public key to the authorized_keys file.

But if you can ssh to the host as any user, and you want ~/.ssh/id_rsa.pub to be included in your_username's keys file, keep it easy on yourself and do this:

locally: cat ~/.ssh/id_rsa.pub #copy the resulting text ssh 192.0.2.0 sudo vi /path/to/your_username's_home_dir/.ssh/authorized_keys remotely: #paste public key contents here ssh [email protected]