0

I've see this post but couldn't exactly follow it. ( https://superuser.com/questions/8077/how-do-i-set-up-ssh-so-i-dont-have-to-type-my-password )
I want to access from machine A(local) to machine B (remote).

What I did was :

  1. I copied the .ssh/rsd_isa.pub of machine A to machine B's .ssh/authorized_keys file.
  2. I checked the write permission is off in machine B's .ssh/authorized_keys file. I tried accessing machine B from machine A like this :
    scp [email protected]:/home/ckim/file1 .
    But it asks me the password.

The link above told me to "load the key to the ssh agent". But I couldn't understand that part. I tried this one (in machine B) :

ckim@ckim-ubuntu-22 ~/.ssh $ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-XXXXXXipqtBR/agent.1234456; export SSH_AUTH_SOCK;
SSH_AGENT_PID=123456; export SSH_AGENT_PID;
echo Agent pid 123456;

So am I supposed to execute this commands where? in machine A? (actually I tried it and also tried ssh-add command, but machine B asks me the password when I access it from machine A). How should I do it?

2
  • There are a few situations when the keys do not work. Most of the time it involves read-write permissions for these key files and their parent folder. See this Q&A for the correct permissions for each file and the parent folder. this applies to both Machines A and B. To see the debut log for ssh use the command ssh -vvvv [email protected]. Note the option is four "v"s. That will give us the most detailed debug log. Copy and paste the output in the question.
    – user68186
    Commented Jun 13 at 23:02
  • Did you create a "passphrase" when you created the private/public key pair in Machine A? Clarify that the scp command is asking for the Machine B's user ckim 's password or the passphrase for the key? Did you use the ssh-copy-id,,,, command to copy the public key or did you use the manual method? The manual method is more prone to create the permission problems.
    – user68186
    Commented Jun 13 at 23:07

2 Answers 2

0

You need to set up ssh-agent correctly on the machine connecting to the server, I just did this today.

in ~/.ssh you need the private key and a config file both with 600 rights.

.ssh/config content

Host server_adress
    HostName server_adress
    User usr_name
    IdentityFile ~/.ssh/private_key
    AddKeysToAgent yes

Then just add the key.

ssh-agent .ssh/private_key

Will ask for the passphrase and save it.

Now just

scp local_path usr_name@server_address:remote_path
3
  • Hi, in machine A, from ssh-agent .ssh/private_key command, I get /home/etri/.ssh/id_rsa: Permission denied. I don't have a file named private_key in machine A's ~/.ssh. What command am I supposed to give?
    – Chan Kim
    Commented Jun 13 at 9:57
  • Then you need to get the private key which you generate on the server, or there already is one generated. Depends pn the server setup and where it is located.
    – Matte
    Commented Jun 13 at 16:04
  • the ~/.ssh/id_rsa is my private key I think.
    – Chan Kim
    Commented Jun 14 at 0:37
0

The ssh-agent command is used to start an agent - the terminal output that you are seeing is shell code that may be eval'd to pass information about that agent to a child process via environment variables. Most Ubuntu flavors instantiate an agent as part of the session setup so you likely already have one running - along with valid SSH_AGENT_PID and SSH_AUTH_SOCK variables in your current shell environment:

$ printenv | grep SSH_
SSH_AUTH_SOCK=/tmp/ssh-gr5zbuTFqETK/agent.1789
SSH_AGENT_PID=1897

To add a key to such an already-running agent you would then use the ssh-add command on the client machine (Machine A). To add the default ~/.ssh/id_rsa key (I'm assuming "rsd_isa" is a typo) you don't even need to specify any additional parameters i.e. just run

ssh-add

If the key requires a passphrase to unlock it, you will be prompted to enter it.

If your private key is saved somewhere other than the default file, you simply pass that location to the ssh-add command e.g.:

ssh-add ~/.ssh/steeldriver_rsa

You can list added keys using ssh-add -l.


The first comment under the accepted answer in your link actually mentions this:

ah, you have to say "ssh-add {path-to-private-key-file}" and then it will ask you for your passphrase. Please make this more explicit in your post. You should also add "Fourth, run ssh". Part of the problem with the documentation with this stuff is that it glosses over seemingly obvious steps that are NOT obvious for someone new to the process who has no idea what's going on and how these programs work together.

4
  • Hi, then where should I run the ssh-add command? In machine A or in machine B? (I want to remotely access machine B from machine A.)
    – Chan Kim
    Commented Jun 14 at 0:41
  • @ChanKim you would run it on Machine A Commented Jun 14 at 0:49
  • It still asks me the password for machine B. I checked the permission of the .ssh directory and the files underneath for both machines.
    – Chan Kim
    Commented Jun 14 at 1:33
  • 1
    @ChanKim so is Machine B actually configured to accept PublicKey authentication? if not, it will fall through to password authentication regardless of what your keys say Commented Jun 14 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .