Scripting login using password authentication

Status
Not open for further replies.

bigphil

Patron
Joined
Jan 30, 2014
Messages
486
Hey guys/gals...I've been searching for the last day on google and here, but cannot find the answer to my question (if you find it quickly, congrats and post the link...you're a better "searcher" than I am ;-)

What I am trying to do is create a script that will login as root (or another privileged account that can create snapshots) from a Windows box. I have been trying to get putty to work, but each time it just says "access denied." The putty event log ends with these two lines: "sent password", and then "password authentication failed" immediately after that.

Here are my settings >
putty for windows version: 0.63
command I'm running: putty.exe nas1 -l root -pw myPassword
I've also tried: putty.exe -ssh -load mySession -pw myPassword
FreeNAS settings: SSH service enabled, login as root with password is enabled, allow password authentication is enabled, the root user account is enabled for password login.

No matter what, each time a run any of the commands, the login prompt comes up and says:
Using username "root".
Access denied
root@nas1's password:

If I then enter the password it lets me right in...its just not taking it from the script and I'm sure its something easy but I'm having a helluva time figuring it out. I don't care about using SSH keys at this point as I know they are more secure, I just want the darn thing to work so I may continue my project!
 

CMDR Sweeper

Dabbler
Joined
Jan 21, 2014
Messages
16
Well for starters you need to have the SSH service enabled, and allow password logins.
Also try to use the IP of the NAS rather than the hostname, it can be somewhat unreliable.
Good thing you are aware of the key issue for now, because what I would do afterwards would be putting a script that denies all other commands than the one you have specified as well as locking it to a specific IP.

What are your SSH service settings in FreeNAS?
 

bigphil

Patron
Joined
Jan 30, 2014
Messages
486
@CMDR Sweeper,
I listed all of the settings in my original post...you must have missed them. Also...I just tried it by IP and the same outcome.
 

CMDR Sweeper

Dabbler
Joined
Jan 21, 2014
Messages
16
That is for Putty, I want to know on the FreeNAS side, do a screenshot of the SSH service in the FreeNAS GUI.
SSH will ask for a password even if it is set to deny password authentication so that's why we will need to see what it is set to on that side first.

EDIT: Are those all the settings you used for it? Nothing else under advanced either?
Putty is primarily a GUI application, does it work for you using it the classic GUI method, can you get connected?
If so, testing something like Cygwin should be your next step.

Another thing worth noticing if you look at the Putty webpage, their CLI version if you want to mess with it is called "plink"
Never tried it as I have used Cygwin myself for similar tasks.
 

bigphil

Patron
Joined
Jan 30, 2014
Messages
486
There are no advanced options set. Just the two check boxes like I listed in my original post. I tried Plink.exe too and it has the same issue. I was able to use the script to connect to an ESXi 5.5 host just fine...it went right in without asking for the password. I think this should work with putty or plink. I want a very lightweight client and putty fits the bill perfectly. Somebody has to know how to get this to work or why its failing.
 

CMDR Sweeper

Dabbler
Joined
Jan 21, 2014
Messages
16
But when you run the raw client for testing purposes does it connect for you or not? I suspect there are some settings thats off so trying it at the barebone will allow you to circle in the problem.
EDIT:
Another thing you can have a look at, see what the other end is doing, it would be easier if you had access to the box via CLI such as SSH, but either through the GUI or physically at the box bring up the /var/log/auth.log and paste it here.

It doesn't contain any passwords but should reveal some clues as to what is going on.
 

bigphil

Patron
Joined
Jan 30, 2014
Messages
486
You must have skimmed too quickly over my initial post. I stated that I was able to connect with the client after it asked for my password. It works just fine when running the putty GUI...just not from the script. I outlined the commands I am running. I wonder if it doesn't like some special characters in the password. I will try creating another account with a simple password.

This is what gets logged in /var/log/auth.log

Failed password for root from 192.168.0.201 port 64000 ssh2
 

CMDR Sweeper

Dabbler
Joined
Jan 21, 2014
Messages
16
Yes special characters could be a problem, clearly something is making the password side of the transmission from your Win box to FreeNAS fail.
Either the script does something odd, or putty isn't transmitting it correctly, at least you now have an angle to work from.
What you can try if the password is an issue is to make a passphrase less key, it isn't that secure but then you can log in without a password and possibly more secure than a short and simple password.
 

bigphil

Patron
Joined
Jan 30, 2014
Messages
486
SON OF A BITCH! It wasn't working because of the password characters. If I wrap the password in quotes ("password") then it works just fine.

Mods: Feel free to mark this as SOLVED. Thanks for the help @CMDR Sweeper
 

CMDR Sweeper

Dabbler
Joined
Jan 21, 2014
Messages
16
Freenas uses OpenSSH, and basically hashes the password so it should support it.
It is possible it is a problem on Putty's side from the CLI, maybe I should make a password with those chars on a generic Linux box and see what it does when I get time.
 
Status
Not open for further replies.
Top