# Changing uid

**URL:** <https://www.ruby-forum.com/t/changing-uid/72764>\
**Category:** Ruby\
**Created:** [October 18, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/changing-uid/72764 "2006-10-18T18:41:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![regularfry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@regularfry](https://www.ruby-forum.com/u/regularfry)\
**Post date:** [October 18, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/changing-uid/72764/1 "2006-10-18T18:41:51Z")

</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?

---

<div class="post-metadata">

**Author:** ![regularfry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@regularfry](https://www.ruby-forum.com/u/regularfry)\
**Post date:** [October 18, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/changing-uid/72764/2 "2006-10-18T18:49:51Z")

</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

---

<div class="post-metadata">

**Author:** ![regularfry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@regularfry](https://www.ruby-forum.com/u/regularfry)\
**Post date:** [October 18, 2006, 6:53pm UTC](https://www.ruby-forum.com/t/changing-uid/72764/3 "2006-10-18T18:53:52Z")

</div>

Alex Y. 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:** ![regularfry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@regularfry](https://www.ruby-forum.com/u/regularfry)\
**Post date:** [October 18, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/changing-uid/72764/4 "2006-10-18T18:59:53Z")

</div>

Daniel B. wrote:

> uid = Etc.getpwnam(‘username’).uid

_That_’s the one! Thanks 🙂
