3

I used this article to set up keys and a user to login to a Ubuntu server from a Windows box using Putty.

I would now like to add an additional ssh user that will login from a MacBook. I used ssh-keygen to generate the local keys but I fail in getting the keys copied up to the server. Here is my bash readout (changed in parts for obvious reasons)

MacBook-Pro:~ joe$ scp -2 -P 50022 -v ~/.ssh/id_rsa.pub [email protected]:
Executing: program /usr/bin/ssh host 111.222.333.444, user newuser, command scp -v -t .
OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to 111.222.333.444 [111.222.333.444] port 50022.
debug1: Connection established.
debug1: identity file /Users/joe/.ssh/id_rsa type 1
debug1: identity file /Users/joe/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '[111.222.333.444]:50000' is known and matches the RSA host key.
debug1: Found key in /Users/joe/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/joe/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/joe/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey). lost connection

3 Answers 3

2

You need to login using the putty on the windows machine and exit the .ssh/authorized_keys file and add the key that you generated on the mac to the file.

Do not run the command

scp -2 -P 50022 -v ~/.ssh/id_rsa.pub [email protected]:

That will over write the existing key on the server, and it will not work either as the server only accepts key logins.

1
  • 1
    I think you mean "edit" and not "exit".
    – Thomas N
    Commented May 5, 2016 at 14:34
2

You'll need to append the contents of Joe's public key (.ssh/id_rsa.pub) to the ~newuser/.ssh/authorized_keys file on the server. I would reccomend using RDP on the macbook to connect to your windows machine, making sure the clipboard is shared. cat the contents of the public key on the macbook, then open a putty window connected to the server. Then run...

cat - >>~newuser/.ssh/authorized_keys

and paste in the key contents, press ctrl+d to close the file.

Alternatively, if you can enable password auth on the server you can use 'ssh-copy-id' from the mac

1

Alt-alternatively, you could simply copy the private key you generated on your Windows box over to your Mac (you might have to convert the key format, see the ssh man pages on your Mac...). No muss, no fuss.

You must log in to answer this question.

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