marchello
Posts: 81
Joined: Fri Oct 11, 2013 8:59 am

connect to ssh with public key

Mon Sep 26, 2016 2:36 pm

Hi all,

I'm about to connect to ssh with public key
ssh user1@host1
Permission denied (publickey).
I already got ssh public key on local rpi.
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 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:
$ 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:
$ 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.
Thanks ahead.

epoch1970
Posts: 5378
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: connect to ssh with public key

Mon Sep 26, 2016 4:21 pm

marchello wrote:I can do it manually, but the question is, where should I copy my local public key if home folder of remote user2@host1 doesn't exist
You should be able to edit your sshd config ...

Code: Select all

$ grep AuthorizedKeysFile /etc/ssh/sshd_config 
#AuthorizedKeysFile	%h/.ssh/authorized_keys
... to use multiple locations, eg

Code: Select all

AuthorizedKeysFile	%h/.ssh/authorized_keys /etc/ssh/homeless-users/%u/authkeys
(%h expands to "~login" and %u to "login")
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “General discussion”