SSH login verification

I need to write a script that check users authenting to a particular server

ssh -l [user] [servername]

if sucessfull

echo loggin sucess

else

echo login invalid

Any Suggestions ?

Not sure if i am right,The message while be displayed only upon the successful login using the below command,

ssh -l user hostname "echo login successful"

Thanks
Nagarajan Ganesan.

Thanks for posting, I just want to validate i dont want to login :slight_smile:

But the above command will prompt for password,if the user is authenticated then the echo command is executed on the remote host and exits.It will not establish a sesssion on the remote host.

Thanks
Nagarajan Ganesan.

Thanks Nagraj,

Can I skip the Question
Are you sure you want to continue connecting (yes/no)? yes[/b]

[sriram@unixguy ~]$ ssh -l root 127.0.0.1 "echo login successful"
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is 8a:57:60:90:49:98:1d:39:50:20:76:f2:5b:cb:a8:4c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts.
root@127.0.0.1's password:
login successful