Page 1 of 1

connect to B3 host using SSH public private key pair

Posted: 29 Nov 2013, 13:27
by OlivierC
Microsoft Windows only users, no Linux box @home except B3 wonderful box
I would like to use public private key pair for ssh authentication
SFTP connection from Windows to /home/user folder
There is a lot of good free clients for Windows.
I will use either:
http://www.swish-sftp.org/ Easy SFTP for windows
http://www.bitvise.com/tunnelier Bitwise Tunnelier

In the past, i was using Windows host and
https://www.itefix.no/i2/copssh Copssh - OpenSSH for Windows
http://diddy.boot-land.net/ssh/files/ssh_copssh.htm

I need some guidance and help to setup B3 host.
Can i just upload SSH Public Key file from Windows explorer to user's /home/USER/.ssh/
Should i give it a specific file name, restart some services.

I'm not a Linux user at all and if i should do all the configuration part from command line, it's not an issue as it's well described and don't miss important parts (from a windows user point of view)
Is it enough to follow tutorial here
http://wiki.excito.org/wiki/index.php/T ... t_Password

I would like NOT to broke others users access to their home folder and NOT disable password-based root access.

Re: connect to B3 host using SSH public private key pair

Posted: 29 Nov 2013, 13:50
by Ubi
Yep the tutorial is all you need. Let us know if it works out. If not then the tutorial needs work =)

Re: connect to B3 host using SSH public private key pair

Posted: 29 Nov 2013, 16:45
by OlivierC
You can generate an SSH key on Windows using the PuTTY SSH client. You can download PuTTY for free from this http://www.chiark.greenend.org.uk/~sgta ... nload.html.
one tutorial here
http://kb.siteground.com/how_to_generat ... ing_putty/

Some additional infos coming from
http://www.walkernews.net/2009/03/22/ho ... ublic-key/
How To Fix “Server Refused Our Key” Error That Caused By Putty Generated RSA Public Key?
Copyright © Walker 22 Mar 2009 16:16
The SSH-2 protocol supports few user authentication types, one of which is public-key cryptography.

Other than security benefit, using public-key cryptography in SSH protocol is relatively easier to implement password-less or non-interactive authentication.

For example, a scheduled shell script can use scp (secure copy) to automate file-transfer between hosts seamlessly in background, without user interaction during authentication stage.

With OpenSSH, default SSH client/server software bundled with most Linux distributions, the ssh-keygen program is used to generate a pair of such cryptographic keys.

As for Putty, popular SSH client suite for Windows, there is this Puttygen program to provide similar functions of ssh-keygen.

However, there is incompatibility issue between RSA type of public key generated by ssh-keygen and Puttygen.

Having said that, you can’t install OpenSSH-generated private key in Putty program. Otherwise, the public-key authentication failed with message that says “Unable to use key file “E:\id_rsa” (OpenSSH SSH-2 private key)”.

Similarly, it’s not possible to install a Puttygen-generated public-key directly into OpenSSH authorized_keys file. If you do so, Putty fails with “Server refused our key” error message during authentication.

So, how to install a Putty-generated RSA type of Public-key in OpenSSH authorized_keys file?


As you’ve seen, the trick is to modified a Puttygen-generated public-key to the format of OpenSSH-generated public-key:

1) Edit Putty-generated public-key file with Vi editor,

2) Delete the first two and the last line,

3) Join the remaining lines into one single line, by using the Shift+J command shortcut. Remember to trim space between two line joined by CTRL+J command.

4) Insert ssh-rsa keyword (with one trailing space) in front of the single line.

5) [ OPTIONAL ] Append Login_ID@Host_name keyword (with a initial space) at the end of the single line (replace Login_ID and Host_name with your SSH login ID and host name accordingly).

6) Append the modified, tweaked Putty-generated public-key (RSA type) to OpenSSH authorized_keys file.

Now, Putty is able to login OpenSSH server with its own set of public-key and private-key pair:
You can also checks comments. some users give hints to solve issues.

I have used mixed instructions coming from both tutorials:
french:
http://wiki.alwaysdata.com/wiki/Se_conn ... 9_publique
english
http://ist.berkeley.edu/as-ag/tools/how ... -directory

copy public key to clipboard. you will use nano text editor to save public key to id_rsa.pub
login using your shell enabled user@b3 account you wish to configure access using key pair

From terminal

Code: Select all

nano
#right click from your mouse to paste content of clipboard 
#save with ^O file name to write id_rsa.pub
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm id_rsa.pub
ls -la
I found different settings for permissions to authorized_keys file

Code: Select all

chmod 600 ~/.ssh/authorized_keys
or

Code: Select all

chmod 644 ~/.ssh/authorized_keys
or

Code: Select all

chmod 640 ~/.ssh/authorized_keys
Which one should i apply for b3 Server SSH-2.0OpenSSH_5.5p1 Debian-6+squeeze3

[edit]: correct typo error

Re: connect to B3 host using SSH public private key pair

Posted: 30 Nov 2013, 03:18
by Ubi
The ssh-copy-id pretty much does all of that for you. But chmod 600 is what you want. The ssh login codes are nobody's business but yours, so no need to give them access

Re: connect to B3 host using SSH public private key pair

Posted: 01 Dec 2013, 08:41
by OlivierC
Password Authentication is insecure.
I already have an x-509 certificate stored on USB token

Found nice tutorial here:
http://trueg.wordpress.com/2012/09/06/u ... ssh-login/
An X.509 certificate contains a private and a public key. As such it is suitable for password-less login via SSH. However, as always with certificates and keys and all that powerful stuff the handling of it all is very clumsy. Kingsley just explained how to setup SSH with X.509 certificates. I will try to add the missing pieces here.

If you do not have a X.509 certificate yet create one with an embedded WebID via the OpenLink YouID service. Make sure the details actually get saved in the last step, for example by posting an identity claim to your Twitter or LinkedIn accounts. This will make the YouID service persist your profile which in turn will result in your new WebID being dereferencable. Kingsley has some nice Linked data details on that in his post.
Export the new certificate which should now be installed in your browser’s key store, into a P12 file. This can be done via the certificate viewer in the browser preferences.
Convert the P12 into PEM format:

# openssl pkcs12 -in MyCert.p12 -out MyCert.pem -nodes

Extract the private key from the P12:

# openssl pkcs12 -in MyCert.p12 -out MySSHKeys.pem -nodes -nocerts

Finally extract the public key from the certificate PEM file and append it to the private key:

# openssl x509 -in MyCert.pem -pubkey -noout >> MySSHKeys.pem

MyCert.pem can now be removed. It is not required anymore.
You can use ssh-keygen to create the line to put into your remote ~/.ssh/authorized_keysfile:

# ssh-keygen -i -m PKCS8 -f MySSHKeys.pem
Win32OpenSSL here: http://slproweb.com/products/Win32OpenSSL.html
include command line tools: openssl and dependencies
Copssh_client_3.1.4 here: https://www.itefix.no/i2/content/copssh-free-edition
include command line tools: ssh-keygen and dependencies

you can follow tutorial here:
http://www.gooze.eu/howto/using-putty-a ... smartcards
or use PuTTY-CAC http://www.risacher.org/putty-cac/
​putty.exe from ​Putty-CAC, an improved version of ​Putty-SC adds MS-CAPI support to putty. Use of CAPI instead of PKCS#11 is easier.

Allow to securely connect to B3 with Private Key stored on USB Token.

Re: connect to B3 host using SSH public private key pair

Posted: 02 Dec 2013, 06:22
by Gordon
If I remember correctly, cygwin ssh will work straight out of the box with the certificate that you created on the B3. Just create a folder named ".ssh" in "%userprofile%" and put the certificate file in there. If you name it "id_rsa" it will log straight on, otherwise you need to specify the name of the certificate file on the commandline. The only issue with this is that you can't stretch the box to allow more characters on a single line - only the number of lines.