# Changing uid

**URL:** <https://rubytalk.org/t/changing-uid/32053>\
**Category:** ruby-talk\
**Created:** [18 October 2006 16:40 UTC](https://rubytalk.org/t/changing-uid/32053 "2006-10-18T16:40:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Young](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alex\_Young](https://rubytalk.org/u/Alex_Young)\
**Post date:** [18 October 2006 16:40 UTC](https://rubytalk.org/t/changing-uid/32053/1 "2006-10-18T16:40:16Z")

</div>

Hi all,

I really should know this, but I can't for the life of me remember how it goes. I want to change users within a Ruby script on Linux, but Process::uid= only to takes an integer. What's the best way to odo the username =\> UID lookup?

> **···**
>
> --  
> Alex

---

<div class="post-metadata">

**Author:** ![Rimantas\_Liubertas](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Rimantas\_Liubertas](https://rubytalk.org/u/Rimantas_Liubertas)\
**Post date:** [18 October 2006 16:49 UTC](https://rubytalk.org/t/changing-uid/32053/2 "2006-10-18T16:49:34Z")

</div>

> I really should know this, but I can't for the life of me remember how  
> it goes. I want to change users within a Ruby script on Linux, but  
> Process::uid= only to takes an integer. What's the best way to odo the  
> username =\> UID lookup?

I wouldn't bet this is the best way, but it seams to work:

require 'etc'  
puts Etc::getpwnam('username')[:uid]

Regards,  
Rimantas

> **···**
>
> --  
> [http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![Daniel\_Berger2](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/daniel_berger2/32/2243_2.png) [@Daniel\_Berger2](https://rubytalk.org/u/Daniel_Berger2)\
**Post date:** [18 October 2006 16:50 UTC](https://rubytalk.org/t/changing-uid/32053/3 "2006-10-18T16:50:13Z")

</div>

Alex Young wrote:

> Hi all,
> 
> I really should know this, but I can't for the life of me remember how  
> it goes. I want to change users within a Ruby script on Linux, but  
> Process::uid= only to takes an integer. What's the best way to odo the  
> username =\> UID lookup?

require 'etc'

uid = Etc.getpwnam('username').uid

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Alex\_Young](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Alex\_Young](https://rubytalk.org/u/Alex_Young)\
**Post date:** [18 October 2006 16:58 UTC](https://rubytalk.org/t/changing-uid/32053/4 "2006-10-18T16:58:14Z")

</div>

Daniel Berger wrote:

> Alex Young wrote:
> 
> > Hi all,
> > 
> > I really should know this, but I can't for the life of me remember how  
> > it goes. I want to change users within a Ruby script on Linux, but  
> > Process::uid= only to takes an integer. What's the best way to odo the  
> > username =\> UID lookup?
> 
> require 'etc'
> 
> uid = Etc.getpwnam('username').uid

\*That\*'s the one! Thanks 🙂

> **···**
>
> --  
> Alex
