Results 1 to 10 of 10

Thread: Command To Generate Random Password String

  1. #1
    Contributors jaysunn's Avatar
    Join Date
    Apr 2009
    Location
    NYC - USA
    Posts
    1,025
    Thanks
    164
    Thanked 153 Times in 132 Posts
    Rep Power
    24

    Default Command To Generate Random Password String

    Hello Nicraft users. I stumbled across this cool command today and I thought I would share it with you all. I have the task as a systems administrator to generate safe passwords for ftp accounts, user accounts etc... Sometimes this can be tedious business. Well I have a cool command tested in BASH and on RHEL that will do this for you


    Check it out!!!!!!


    Code:
    [root@uranium ~]# < /dev/urandom tr -dc A-Za-z0-9_ | head -c8
    jO_00rTf
    You can change how many characters you want your password by the value -c*

    Now don't waste to much of your day pressing enter over and over checking how random these strings are. I spent a solid hour today. HEHE

    Jaysunn

  2. The Following User Says Thank You to jaysunn For This Useful Post:

    chimu (27th August 2009)

  3. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,512
    Thanks
    17
    Thanked 803 Times in 511 Posts
    Rep Power
    10

    Default

    I've added the following to my ~/.bashrc:
    PHP Code:
    genpasswd() { 
        
    local l=$1
               
    "$l== "" ] && l=16
              tr 
    -dc A-Za-z0-9_ < /dev/urandom head -${l} | xargs 

    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  4. The Following 2 Users Say Thank You to nixcraft For This Useful Post:

    chimu (27th August 2009), jaysunn (27th August 2009)

  5. #3
    Contributors jaysunn's Avatar
    Join Date
    Apr 2009
    Location
    NYC - USA
    Posts
    1,025
    Thanks
    164
    Thanked 153 Times in 132 Posts
    Rep Power
    24

    Default

    I added that as well to my ~.bashrc, to test what you have done. When I login, I get the same prompt. What should occur? From the code it looks like the obvious of a random string of some sort.

    Can you please elaborate on that?

    Thanks,

    Jaysunn

    I SEEEEEEE,

    I just added a command called genpasswd. SWEET.

    Jaysunn
    Last edited by jaysunn; 27th August 2009 at 01:40 AM. Reason: Not paying attention

  6. #4
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,512
    Thanks
    17
    Thanked 803 Times in 511 Posts
    Rep Power
    10

    Default

    File is ~/.bashrc and NOT ~.bashrc

    Just type genpasswd to display password, it accepts a password length on fly:
    Code:
    genpasswd
    genpasswd 10
    genpasswd 24
    SxdWVJW5pijD655_hEiOYHJ5
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  7. #5
    Contributors chimu's Avatar
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    28
    Thanked 6 Times in 5 Posts
    Rep Power
    10

    Default

    may i ask, where did you find command in first place? i'm sure it is not from the man page..lol

    ps: this should in tutorial or shell forum

  8. #6
    Contributors jaysunn's Avatar
    Join Date
    Apr 2009
    Location
    NYC - USA
    Posts
    1,025
    Thanks
    164
    Thanked 153 Times in 132 Posts
    Rep Power
    24

    Default

    I found this on a pretty neat site:

    [shell-fu:home]$

    However you are correct about this going into a different forum. I did not expect to get a much great tip from Nixcraft. However I always manage to get great info here.

    Jaysunn

  9. #7
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,512
    Thanks
    17
    Thanked 803 Times in 511 Posts
    Rep Power
    10

    Talking

    Quote Originally Posted by jaysunn View Post
    I found this on a pretty neat site:

    [shell-fu:home]$
    Great site and thread moved to shell scripting forum.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  10. #8
    Senior Member
    Join Date
    Jun 2007
    Location
    Hyderabad, AP, India
    Posts
    806
    Thanks
    44
    Thanked 55 Times in 48 Posts
    Rep Power
    13

    Default nice command

    but facing issue with out put as below
    [root@test ~]# getpasswd
    1kMg9EF9[root@test ~]#

    cant we get like this?

    [root@test ~]# getpasswd
    1kMg9EF9
    [root@test ~]#

    ???????

  11. #9
    Contributors jaysunn's Avatar
    Join Date
    Apr 2009
    Location
    NYC - USA
    Posts
    1,025
    Thanks
    164
    Thanked 153 Times in 132 Posts
    Rep Power
    24

    Default

    Yes if you enter the command that I first posted just as is in BASH in RHEL. You get this:


    Code:
    [root@radio5 ~]# < /dev/urandom tr -dc A-Za-z0-9_ | head -c8
    lQIvHjtj[root@radio5 ~]#
    If you take this example one step further and edit your ~/.bashrc file and add the code that Nixcraft posted you can get a cleaner output.

    Code:
    [root@radio5 bin]# vi ~/.bashrc
    Add this to the top of the file:

    PHP Code:
    genpasswd() { 
        
    local l=$1
               
    "$l== "" ] && l=16
              tr 
    -dc A-Za-z0-9_ < /dev/urandom head -${l} | xargs 


    Next you type the following to generate a random password string:

    Code:
    [root@radio5 ~]# genpasswd 10
    nCfKSfRxgU
    [root@radio5 ~]#
    You can alter the number 10 to whatever to get different values.

    HTH,

    Jaysunn

  12. #10
    Member
    Join Date
    Jun 2011
    Location
    India, Bangalore
    Posts
    31
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by jaysunn View Post
    Hello Nicraft users. I stumbled across this cool command today and I thought I would share it with you all. I have the task as a systems administrator to generate safe passwords for ftp accounts, user accounts etc... Sometimes this can be tedious business. Well I have a cool command tested in BASH and on RHEL that will do this for you


    Check it out!!!!!!


    Code:
    [root@uranium ~]# < /dev/urandom tr -dc A-Za-z0-9_ | head -c8
    jO_00rTf
    You can change how many characters you want your password by the value -c*

    Now don't waste to much of your day pressing enter over and over checking how random these strings are. I spent a solid hour today. HEHE

    Jaysunn
    Good code.

    This inspired me to come up with my version which includes the special characters in the password. I use this kind of script to generate passwords for the new users (to make their life hell with these passwords)

    Here it is:
    PHP Code:
    head -c 500 /dev/urandom tr -dc 'a-zA-Z0-9~!@#$%^&*-_' fold -w 8 head -n 1 
    You can change the count 8 in fold -w 8 to make the password string shorter or longer depending on your needs. Also, if you want multiple passwords at one go, you cant change the number in head -n 1 to something else

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Shell Script To Generate License Keys
    By please in forum Shell scripting
    Replies: 2
    Last Post: 4th January 2009, 06:03 PM
  2. httpd.conf deleted! How to re-generate? Any Scripts?
    By vivekv in forum Shell scripting
    Replies: 1
    Last Post: 17th July 2008, 05:13 PM
  3. httpd.conf deleted! How to re-generate?
    By vivekv in forum Getting started tutorials
    Replies: 2
    Last Post: 17th January 2008, 03:45 PM
  4. linux command search server for string
    By chimu in forum Linux software
    Replies: 2
    Last Post: 26th July 2006, 12:40 AM
  5. example for string connect to a command.
    By ryan in forum Shell scripting
    Replies: 2
    Last Post: 22nd February 2005, 01:05 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •