Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

connect to ssh with public key

Off-Topic discussions about science, technology, and non Debian specific topics.
Post Reply
Message
Author
marchello
Posts: 60
Joined: 2013-10-08 08:47

connect to ssh with public key

#1 Post by marchello »

Hi all,
This is not debian question, but please have mercy :)
I'm about to connect to ssh with public key

Code: Select all

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:

Code: Select all

    $ 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:

Code: Select all

    $ 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.

fsmithred
Posts: 1873
Joined: 2008-01-02 14:52

Re: connect to ssh with public key

#2 Post by fsmithred »

If you can connect as user2 (I'm assuming that user2 has a place to save files. I don't know what you mean that user2 has no home directory.)

Code: Select all

sftp -o IdentityFile=<user2's private key>  user2@host1
put <user1's public key>
Then

Code: Select all

ssh user2@host1
chown user1 <user1's public key>
su user1
cat <user1's public key> >> /home/user1/.ssh/authorized_keys
rm user1's public key
exit
exit 
If you cannot connect as user2 or any other user, then you need to either enable password logins again, or you need to put the public key on a usb thumb drive and plug it into host1 to copy the file.

Post Reply