sshpass & ssh does not cooperate?

P

postcd

Guest
Hello,

around 3 years back i used sshpass to input password to the ssh command and i believe it worked.
But now it does not work.

# sshpass -V | head -n 1
sshpass 1.05 (C) 2006-2011 Lingnu Open Source Consulting Ltd.
# which sshpass;which ssh;cat /etc/red*
/usr/bin/sshpass
/usr/bin/ssh
CentOS release 5.11 (Final)
manual: https://linux.die.net/man/1/sshpass

So i run the command:
# ps auxf|grep ssh;/usr/bin/sshpass -p 3d6b1e9db8 /usr/bin/ssh -f -N -D 0.0.0.0:1080 localhost;ps auxf|grep ssh
root 858 0.0 0.1 62688 1196 ? Ss Mar13 0:00 /usr/sbin/sshd
root 5989 0.0 0.4 88112 3728 ? Ss 04:06 0:00 \_ sshd: root@pts/1
root 6071 0.0 0.4 88112 3728 ? Ss 05:22 0:00 \_ sshd: root@pts/2
root 6393 0.0 0.0 6052 600 pts/0 S+ 05:55 0:00 \_ grep ssh
root 858 0.0 0.1 62688 1196 ? Ss Mar13 0:00 /usr/sbin/sshd
root 5989 0.0 0.4 88112 3728 ? Ss 04:06 0:00 \_ sshd: root@pts/1
root 6071 0.0 0.4 88112 3728 ? Ss 05:22 0:00 \_ sshd: root@pts/2
root 6396 0.0 0.4 86044 3252 ? Ds 05:55 0:00 \_ sshd: root [priv]
root 6400 0.0 0.0 6052 596 pts/0 S+ 05:55 0:00 \_ grep ssh

and i do not see it setup a SSH connection. When i use bad password, it reports denied access.

command ssh h -f -N -D 0.0.0.0:1080 localhost is working very well without any problem but i wanted to show you something i noticed when i run with verbose enabled :

[root@hefwrflk ~]# ssh -v -f -o StrictHostKeyChecking=no -N -D 0.0.0.0:1080 localhost
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
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_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr 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 'localhost' is known and matches the RSA host key.
debug1: Found key in /root/.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: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
root@localhost's password:
debug1: Authentication succeeded (password).
debug1: Local connections to 0.0.0.0:1080 forwarded to remote address socks:0
debug1: Local forwarding listening on 0.0.0.0 port 1080.
debug1: channel 0: new [port listener]
[root@hefwrflk ~]# debug1: Entering interactive session.

And SSHPASS:

[root@hefwrflk ~]# sshpass -p myrootpassword ssh -v -f -o StrictHostKeyChecking=no -N -D 0.0.0.0:1080 localhost
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
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_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr 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 'localhost' is known and matches the RSA host key.
debug1: Found key in /root/.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: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
debug1: Authentication succeeded (password).
debug1: Local connections to 0.0.0.0:1080 forwarded to remote address socks:0
debug1: Local forwarding listening on 0.0.0.0 port 1080.
debug1: channel 0: new [port listener]
[root@hefwrflk ~]#

I noticed that with sshpass the last line "Entering interactive session." is not present in debug log.

When i disabled GSSAPIAuthentication, i do not see any errors:

[root@hefwrflk /]# sshpass -p "myrootpassword" ssh -v -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -f -N -D 0.0.0.0:1080 localhost
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
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_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr 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 'localhost' is known and matches the RSA host key.
debug1: Found key in /root/.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: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
debug1: Authentication succeeded (password).
debug1: Local connections to 0.0.0.0:1080 forwarded to remote address socks:0
debug1: Local forwarding listening on 0.0.0.0 port 1080.
debug1: channel 0: new [port listener]

tail /var/log/secure shows:
Mar 14 07:41:56 hefwrflk sshd[6690]: Accepted password for root from 127.0.0.1 port 36949 ssh2
Mar 14 07:41:56 hefwrflk sshd[6690]: pam_unix(sshd:session): session opened for user root by (uid=0)
Mar 14 07:41:56 hefwrflk sshd[6690]: pam_unix(sshd:session): session closed for user root

Is there any workaround so i can run that ssh command from within bash script without need to input password myself? (i know it is security issue)

Thank You
 
Last edited:


Now, I'm no sys-admin - but I'd say your best bet would be to set up some ssh keys.
I used to have a couple of servers on my home network a few years ago. I used to access them over ssh using encrypted public keys, rather than using a password.

Once the keys are set-up and working with ssh, you can disable ssh password logins on the remote server/s.
 
Set up public/private keys using ssh-keygen, then upload ONLY the PUBLIC key to the server using ssh-copy-id, and then you only need to type "ssh example", if you setup the site as "Host example" in your ~/.ssh/config file.

Also, PLEASE, PLEASE set PermitRootLogin, on the servers, to "no" to force the user to login as a regular user. Also PLEASE, PLEASE change the default ssh port (22) on all the servers you have the authority to do, (Or take the Sys Admin for the server in question, out for a couple of good beers!) to a different (Much higher) port number! I speak from experience of hundreds if not thousands attempted logins per day on an open port 22! Of course, I also ass/u/me that your user password is NOT "password"! ;^)
 
Thx for advice regarding SSH keys. So i was googling and here are commands that i tried:

ssh-keygen -t rsa
(enter to every prompt)
ssh-copy-id root@localhost
then:
ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -f -N -D 0.0.0.0:1080 localhost

I did it wrong? If so, how better i can do it please? Thx
 
havent you been working with ssh for years now? and it took you longer to post your 'question' than it would have taken you to just try it and find out if it worked.

and are you seriously logging in as ROOT over a network? thats incredibly dangerous, stupid, and lazy. if you keyswap your normal account, you can omit all the flags and just type "ssh user@host", and get in. need root from there, type in su or use sudo for what it was written for.
 
i do not need to login, i need to setup reverse proxy if i understand good. if anyone knows right way or can narrow my above mentioned command, please kindly contribute. Thank You
 
you dont understand and if you arent clear after 3 years you should hire someone that knows what theyre doing. you could put 'ssh reverse proxy' into google if thats not too hard for you and read the first result that tells you how to do it. or you could use ssh-keys as everyone has told you and followed the howtos for that too. all that dosnt matter, since your an absolute moron if you log in as root over a network for any reasons.
 
Solution not found yet, i read some articles about this, but do not understand. If anyone can narrow my command it would be helpful.
 
not sure what you dont understand. how simple does it have to be before you get it? 3yrs now and you cant understand basic ssh commands? or any of the gazillion hits that come up in a search? or that logging in as root is stupid on a global scale? dude, i dont think anyone, anywhere is going to be able to explain it to you. tell your company to hire an admin that knows what their doing.
 
ssh is used by a user (preferably NOT root) to connect to another computer (server), NOT the "localhost", the local computer.

As a regular user, you set up public and private keys with ssh-keygen, putting the PUBLIC key ONLY to the server using ssh-copy-id, or manually.

Please reread my other suggestions in #3.

If you still have problems understanding this, then you need to bring in someone locally to assist you in setting this up. Not much more advice we can give you.
 
Last edited:
ssh is used by a user (preferably NOT root) to connect to another computer (server), NOT the "localhost", the local computer.
Thx, but my initial command (post 1 of this thread) worked without me setting up anything on the client. It just setup "proxy" on the server and then i could poiunt my web browser to this server IP and port and it worked to do proxying. So i think you did not understood what i want to do. My aim is not to set anything on the client (which is Windows PC). Need setup SSH "reverse(?)" proxy on server...
 
Sorry, but you gave me no indication of any proxy reverse or otherwise.

Never worked with anything like this so I can't help you out.

Please be more specific what you are attempting to do first before showing error messages or debug output.
 
Thx, but my initial command (post 1 of this thread) worked without me setting up anything on the client. It just setup "proxy" on the server and then i could poiunt my web browser to this server IP and port and it worked to do proxying. So i think you did not understood what i want to do. My aim is not to set anything on the client (which is Windows PC). Need setup SSH "reverse(?)" proxy on server...
great so did you try putting "how to set up reverse proxy with ssh on linux" into google and pressing the enter key? or is that too complicated? logging in as root is stupid and you ignore everyone telling you that. you can do passwordless ssh from windows to linux easy with putty, so whats your problem?
 

Members online


Top