ssh passwordless


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh passwordless
# 1  
Old 06-08-2010
ssh passwordless

Hi,

I want to login to a remote server and sftp files without password prompting. So, I created private-public key pair as follows:

Code:
 
[user1@server1.com .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
c1:21:e 3:01:26:0d:f7:ec:52:0e:0c:90:9b:6e:d8:47 user1@server1.com

NOTE: I haven't provided passphrase

Now on the "remote" server say, server2.com. I appended the content of id_rsa.pub file to <server2.com's home>/.ssh/authorized_keys file which is ssh-rsa <lot of chars> user1@server1.com

Then with everything set-up I tried:
Code:
sftp user2@server2.com
user2@server2.com's password:

but boom! It still asks for password!!

someone told me I can find problem through ssh-v command so I tried it and this what it has to say:
Code:
 
[user1@server1.com ~]$ ssh -v user2@server2.com
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data <user1 home>/.ssh/config
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to server2.com [IP ADDRESS] port 22.
debug1: Connection established.
debug1: identity file <user1 home>/.ssh/identity type -1
debug1: identity file <user1 home>/.ssh/id_rsa type 1
debug1: identity file <user1 home>/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc 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 'server2.com' is known and matches the RSA host key.
debug1: Found key in <user1 home>/.ssh/known_hosts:1
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,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: <user1 home>/.ssh/identity
debug1: Offering public key: <user1 home>/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Trying private key: <user1 home>/.ssh/id_dsa
debug1: Next authentication method: password
user2@server2.com's password:

but I am not able to debug it!! Can anyone here please help me?

-dips
# 2  
Old 06-08-2010
please try and write output here
Code:
ssh -vv user2@server2.com

# 3  
Old 06-08-2010
Please check, that the key in the server's authorized_keys file is in fact a single line. Since the key is quite long, it sometimes happens that the key gets split into two or even more lines by copy-and-paste.
# 4  
Old 06-08-2010
Try renaming authorized_keys to authorized_keys2. Most recent Unix flavors prefer protocol 2.

Note: Newer OpenSSH version accept both names for protocol 1 and 2. Smilie

Also, make sure that .ssh folder has permissions 0700, and authorized_keys 0644.
# 5  
Old 06-08-2010
Best way to according to me
let investigate secure file so look tail -f /var/log/secure
if you see like key_read then your pub key isnt correct Smilie
# 6  
Old 06-08-2010
Hi,

Here's the output of ssh -vv user2@server2.com
Code:
 
[user1@server1.com ~]$ ssh -vv user2@server2
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data <user 1 home>/.ssh/config
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to server2 [IP ADDRESS] port 22.
debug1: Connection established.
debug1: identity file <user 1 home>/.ssh/identity type -1
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type '-----END'
debug1: identity file <user 1 home>/.ssh/id_rsa type 1
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug2: key_type_from_name: unknown key type '-----END'
debug1: identity file <user 1 home>/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_init: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_init: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 132/256
debug2: bits set: 513/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'server2' is known and matches the RSA host key.
debug1: Found key in <user 1 home>/.ssh/known_hosts:1
debug2: bits set: 514/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: <user 1 home>/.ssh/identity ((nil))
debug2: key: <user 1 home>/.ssh/id_rsa (0x552abfea30)
debug2: key: <user 1 home>/.ssh/id_dsa (0x552abfea50)
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug2: we sent a gssapi-with-mic packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug2: we sent a gssapi-with-mic packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug2: we did not send a packet, disable method
debug1: Next authentication method: publickey
debug1: Trying private key: <user 1 home>/.ssh/identity
debug1: Offering public key: <user 1 home>/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Offering public key: <user 1 home>/.ssh/id_dsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
user2@server2's password:

Quote:
Please check, that the key in the server's authorized_keys file is in fact a single line. Since the key is quite long, it sometimes happens that the key gets split into two or even more lines by copy-and-paste.
I had already ensured that the key in authorized_keys file is a single line only I re-checked it; its a single line.

Quote:
Also, make sure that .ssh folder has permissions 0700, and authorized_keys 0644.
Ensured. It has correct permissions.

Quote:
Try renaming authorized_keys to authorized_keys2. Most recent Unix flavors prefer protocol 2.

Note: Newer OpenSSH version accept both names for protocol 1 and 2. Smilie
I am working on
Code:
[user1@server1.com ~]$ uname -a
Linux server1.com 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:33:05 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

I am not allowed to rename authorized_keys to authorized_keys2 as that file already has public keys from other sites as well.

Quote:
Best way to according to me
let investigate secure file so look tail -f /var/log/secure
if you see like key_read then your pub key isnt correct Smilie
I don't have permissions to read this file :-(

-dips
# 7  
Old 06-09-2010
I think your server2 in sshd doesnt find public key that came from your ssh client for ssh request passwordless..
So you must check the sshd conf in server2 where looks for..

Code:
 
cat /etc/ssh/sshd_config | grep "AuthorizedKeysFile"

And you must sure append the your pubkey in correct authkeys file in server2..

Good lucks
Regards ygemici
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passwordless ssh for different user

Hello Folks, I lost touch in ssh key gen topics. I am in need of ssh to a server without password, kindly help me in configuring. I have two servers, server1 with user name apha & server1 with user name beta. I need to ssh to the server2 from server1 with respective users, Manually i... (3 Replies)
Discussion started by: Thala
3 Replies

2. Shell Programming and Scripting

Ssh passwordless authentication

Hey team I have to enable password less authentication betweeen A to B server and A to C server and A to D server. For this I generated a ssh key on server A using ssh-keygen command and copied the key using ssh-copy-id command to B, C and D server. Everything is working fine as of now but... (5 Replies)
Discussion started by: Sandeep_sandy
5 Replies

3. Solaris

Passwordless ssh for root

Hi Experts, I am trying to setup passwordless ssh for root between two of my solaris servers(say A & B). I have exchanged the public keys between both servers. Password less ssh working fine while I try to connect from Server A to Server B. However it is still asking password... (6 Replies)
Discussion started by: sai_2507
6 Replies

4. Ubuntu

Passwordless ssh authentication fails

Unable to set ssh passwordless authentication I am unable to ssh with passwordless authentication from Windows client onto UBuntu server. The ssh version on UBuntu is OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e , while SSH on Windows Client is OpenSSH_5.1p1, OpenSSL 0.9.8k. I turned on ssh... (5 Replies)
Discussion started by: tkota
5 Replies

5. UNIX for Advanced & Expert Users

Passwordless ssh

Hi I have created a user on a linux server and created a passwordless ssh key. I've echoed the key into the authorized_keys file for the user. I've added a series of forced commands to the key. From my laptop - logged in as myself - I can ssh into the server as that user and the commands... (3 Replies)
Discussion started by: steadyonabix
3 Replies

6. Shell Programming and Scripting

passwordless ssh

My main concern is, i have to login into 300 linux server and all are having same userid and password. I dont want to create any key for each server to login . Is there a way to run the shell script ? (3 Replies)
Discussion started by: Mani2512
3 Replies

7. UNIX for Dummies Questions & Answers

passwordless ssh

hi, i have tried with passwordless shh in google.. i followed the below steps ... user:~> ssh-keygen -t rsa Enter file in which to save the key (/home/cantin/.ssh/id_rsa):key.txt Enter passphrase (empty for no passphrase): Enter same passphrase again: till this step i... (0 Replies)
Discussion started by: arunmanas
0 Replies

8. AIX

passwordless ssh for non-root user???

hi all I have a problem to set up the password ssh login for a non-root user. what I want to do is that non-root user in host A logs into host B without password prompted. what I did listed as the following steps. 1. genarate a pair of keys from host A. ssy-keygen -t rsa -N "" -f... (9 Replies)
Discussion started by: rs6000er
9 Replies

9. HP-UX

Help on passwordless ssh...

Hi, Can someone help me on ssh-keygen usage...? I used ssh-keygen after which "id.pub" file was generated in system1's > .ssh directory... I copied the same into the remote system system2 > .ssh directory as "authorized_keys" file. Now i tried ssh connection from system 1 to system... (7 Replies)
Discussion started by: EmbedUX
7 Replies

10. AIX

Passwordless authentication via SSH

I am trying to implement passwordless authentication via ssh2. I have used the well documented technique of generating a key pair with a blank passphrase on my client machine, and installing the public key on the destination server (AIX 5.3) in the user's .ssh2 directory. I have used this technique... (1 Reply)
Discussion started by: RegX
1 Replies
Login or Register to Ask a Question