0

I'm about to connect to ssh with public key

ssh user1@host1
Permission denied (publickey).

I already got ssh public key on local machine. I know I should copy public key into remote machine first, the problem is that password auth is forbidden. I can connect with user2@host1 and my ssh key are already copied into this user2 ~/.ssh/authorized_keys file. I can do it manually, but the question is, where should I copy my local public key manually if home folder of remote user2@host1 doesn't exist?

It worked with ssh-copy-id before when password authorisation was allowed. How do I perform it now?

local machine:

$ cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
NAME="Raspbian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=raspbian
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

remote machine:

$ cat /etc/*-release                                   
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
NAME="Ubuntu"
VERSION="14.04.5 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.5 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

Please advise.

  • Do you mean home folder of user1 does not exist? – alex_d Sep 26 '16 at 15:46
  • alex_d, that's right, home folder of user1 does not exist. – marco Sep 26 '16 at 15:49
  • And does user2 have sudo privileges? – alex_d Sep 26 '16 at 15:51
  • I can request it, so assume the answer is yes. – marco Sep 26 '16 at 15:55
0

Since you can log on with user2, the easiest solution would be to create user1's home and ssh directories (/home/user1, /home/user1/.ssh), which will likely require superuser privileges, and either copy user2's authorized_keys file to user1 (if the all of the keys are the same), or (more secure but slightly more complicated) copy user1's public key to the remote machine with scp. From the local machine:

scp ~/.ssh/pubkey_file user2@host1:/some/folder/

and then place the key into /home/user1/.ssh/authorized_keys. Logged in to the remote machine,

cat /some/folder/pubkey_file > /home/user1/.ssh/authorized_keys

You'll want to make sure that all of the folder and file privileges are set correctly, of course. Easiest is to compare them to the privileges on user2's ssh files and folders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.