# Linux authentification check?

**URL:** <https://rubytalk.org/t/linux-authentification-check/32721>\
**Category:** ruby-talk\
**Created:** [7 November 2006 15:48 UTC](https://rubytalk.org/t/linux-authentification-check/32721 "2006-11-07T15:48:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RHaus](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RHaus](https://rubytalk.org/u/RHaus)\
**Post date:** [7 November 2006 15:48 UTC](https://rubytalk.org/t/linux-authentification-check/32721/1 "2006-11-07T15:48:27Z")

</div>

Is there a library or some other way to simply check whether a  
user/password combination is valid for the Linux machine I am  
running on? No need to actually switch the current user, change  
the effective group or user id etc. All I want is to make sure that  
the username exists and that the password is valid for that user.  
(I want to allow only those users to use a certain service running  
within a restricted server that have a userid defined on that machine)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Jon\_Lim](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@Jon\_Lim](https://rubytalk.org/u/Jon_Lim)\
**Post date:** [7 November 2006 15:54 UTC](https://rubytalk.org/t/linux-authentification-check/32721/2 "2006-11-07T15:54:24Z")

</div>

ruby-pam might be what you're looking for.

> **···**
>
> On 07/11/06, Roman Hausner \<roman.hausner@gmail.com\> wrote:
> 
> > Is there a library or some other way to simply check whether a  
> > user/password combination is valid for the Linux machine I am  
> > running on? No need to actually switch the current user, change  
> > the effective group or user id etc. All I want is to make sure that  
> > the username exists and that the password is valid for that user.  
> > (I want to allow only those users to use a certain service running  
> > within a restricted server that have a userid defined on that machine)
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> --
> 
> > **[snowblink](https://snowblink.co.uk/)**
> >
> > snowblink.co.uk : Homepage

---

<div class="post-metadata">

**Author:** ![RHaus](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RHaus](https://rubytalk.org/u/RHaus)\
**Post date:** [7 November 2006 16:55 UTC](https://rubytalk.org/t/linux-authentification-check/32721/3 "2006-11-07T16:55:12Z")

</div>

Jon Lim wrote:

> ruby-pam might be what you're looking for.

It seems this needs the system PAM libraries to be installed.  
I am not really intending to switch the authentification methods of  
the linux box or anything, I just want ruby to use the existing  
authentification method to check for a valid username/password.

Maybe I am missing something, but I was expecting something like  
boolean = validate(username,password)  
and be done with it 🙂

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Wilson\_Bilkovich](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/wilson_bilkovich/32/8247_2.png) [@Wilson\_Bilkovich](https://rubytalk.org/u/Wilson_Bilkovich)\
**Post date:** [7 November 2006 17:49 UTC](https://rubytalk.org/t/linux-authentification-check/32721/4 "2006-11-07T17:49:37Z")

</div>

Are you saying that PAM isn't installed on your Linux box?  
If it is, you should use it. /etc/passwd is definitely not the last  
word in login authentication. Be careful about your assumptions, or  
else the guy with the smartcard won't be able to use your Ruby  
program.

> **···**
>
> On 11/7/06, Roman Hausner \<roman.hausner@gmail.com\> wrote:
> 
> > Jon Lim wrote:  
> > \> ruby-pam might be what you're looking for.  
> > It seems this needs the system PAM libraries to be installed.  
> > I am not really intending to switch the authentification methods of  
> > the linux box or anything, I just want ruby to use the existing  
> > authentification method to check for a valid username/password.
> > 
> > Maybe I am missing something, but I was expecting something like  
> > boolean = validate(username,password)  
> > and be done with it 🙂

---

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [7 November 2006 19:09 UTC](https://rubytalk.org/t/linux-authentification-check/32721/5 "2006-11-07T19:09:58Z")

</div>

Would LDAP do it?  
Just curious!

> **···**
>
> On 11/7/06, Wilson Bilkovich \<wilsonb@gmail.com\> wrote:
> 
> > On 11/7/06, Roman Hausner \<roman.hausner@gmail.com\> wrote:  
> > \> Jon Lim wrote:  
> > \> \> ruby-pam might be what you're looking for.  
> > \> It seems this needs the system PAM libraries to be installed.  
> > \> I am not really intending to switch the authentification methods of  
> > \> the linux box or anything, I just want ruby to use the existing  
> > \> authentification method to check for a valid username/password.  
> > \>  
> > \> Maybe I am missing something, but I was expecting something like  
> > \> boolean = validate(username,password)  
> > \> and be done with it 🙂  
> > \>
> > 
> > Are you saying that PAM isn't installed on your Linux box?  
> > If it is, you should use it. /etc/passwd is definitely not the last  
> > word in login authentication. Be careful about your assumptions, or  
> > else the guy with the smartcard won't be able to use your Ruby  
> > program.

---

<div class="post-metadata">

**Author:** ![RHaus](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RHaus](https://rubytalk.org/u/RHaus)\
**Post date:** [7 November 2006 22:40 UTC](https://rubytalk.org/t/linux-authentification-check/32721/6 "2006-11-07T22:40:12Z")

</div>

Wilson Bilkovich wrote:

> **···**
>
> > On 11/7/06, Roman Hausner \<roman.hausner@gmail.com\> wrote:
> > 
> > > 
> > 
> > Are you saying that PAM isn't installed on your Linux box?  
> > If it is, you should use it. /etc/passwd is definitely not the last  
> > word in login authentication. Be careful about your assumptions, or  
> > else the guy with the smartcard won't be able to use your Ruby  
> > program.
> 
> The linux machine is not under my control. I am just the one who writes  
> that server program.
> 
> As it turns out, it already would be sufficient if I could do the same  
> that the "crypt" function achieves under perl.  
> Perl does have this as part of the core language -- how can I access  
> this function in ruby?
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [7 November 2006 22:47 UTC](https://rubytalk.org/t/linux-authentification-check/32721/7 "2006-11-07T22:47:15Z")

</div>

Roman Hausner wrote:

> As it turns out, it already would be sufficient if I could do the same  
> that the "crypt" function achieves under perl.  
> Perl does have this as part of the core language -- how can I access this function in ruby?

$ ri String#crypt | cat  
----------------------------------------------------------- String#crypt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str.crypt(other\_str) =\> new\_str

> **···**
>
> ------------------------------------------------------------------------  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Applies a one-way cryptographic hash to str by invoking the  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;standard library function crypt. The argument is the salt string,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;which should be two characters long, each character drawn from  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[a-zA-Z0-9./].
> 
> --  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

---

<div class="post-metadata">

**Author:** ![Gabriele\_Marrone](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@Gabriele\_Marrone](https://rubytalk.org/u/Gabriele_Marrone)\
**Post date:** [7 November 2006 22:48 UTC](https://rubytalk.org/t/linux-authentification-check/32721/8 "2006-11-07T22:48:19Z")

</div>

Ruby does too, as a String method:

----------------------------------------------------------- String#crypt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str.crypt(other\_str) =\> new\_str

> **···**
>
> Il giorno 07/nov/06, alle ore 23:40, Roman Hausner ha scritto:
> 
> > As it turns out, it already would be sufficient if I could do the same  
> > that the "crypt" function achieves under perl.  
> > Perl does have this as part of the core language -- how can I access  
> > this function in ruby?
> 
> ------------------------------------------------------------------------  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Applies a one-way cryptographic hash to str by invoking the  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;standard library function crypt. The argument is the salt string,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;which should be two characters long, each character drawn from  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[a-zA-Z0-9./].

---

<div class="post-metadata">

**Author:** ![snacktime](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@snacktime](https://rubytalk.org/u/snacktime)\
**Post date:** [8 November 2006 00:50 UTC](https://rubytalk.org/t/linux-authentification-check/32721/9 "2006-11-08T00:50:46Z")

</div>

> The linux machine is not under my control. I am just the one who writes  
> that server program.
> 
> As it turns out, it already would be sufficient if I could do the same  
> that the "crypt" function achieves under perl.

Only if your server runs as root though, and only if the linux server  
uses the password file for authentication.

---

<div class="post-metadata">

**Author:** ![RHaus](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RHaus](https://rubytalk.org/u/RHaus)\
**Post date:** [7 November 2006 23:09 UTC](https://rubytalk.org/t/linux-authentification-check/32721/10 "2006-11-07T23:09:00Z")

</div>

Gabriele Marrone wrote:

> **···**
>
> > Il giorno 07/nov/06, alle ore 23:40, Roman Hausner ha scritto:
> > 
> > > As it turns out, it already would be sufficient if I could do the same  
> > > that the "crypt" function achieves under perl.  
> > > Perl does have this as part of the core language -- how can I access  
> > > this function in ruby?
> > 
> > Ruby does too, as a String method:
> > 
> > ----------------------------------------------------------- String#crypt  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str.crypt(other\_str) =\> new\_str
> 
> Thanks!  
> I was looking in all the wrong places -- wow that you say it, it seems  
> natural to have it as a String method 🙂
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
