How to use /dev/(u)random












24














How can I use /dev/(u)random on Ubuntu or any *nix sistems?



I tried this but it says permission denied.

Note : I also tried as root.



/dev/(u)random
sudo /dev/(u)random
sudo -s; /dev/(u)random









share|improve this question




















  • 1




    Please notice that these commands should be used only, when you really need high quality random data, typically in order to create good passwords. Otherwise there are more light-weight alternatives, for example the shell environment 'variable' RANDOM to create random positive integer numbers: echo $RANDOM, and the program shuf to generate random permutations, for example play in random order from a playlist.
    – sudodus
    Apr 18 '18 at 20:31


















24














How can I use /dev/(u)random on Ubuntu or any *nix sistems?



I tried this but it says permission denied.

Note : I also tried as root.



/dev/(u)random
sudo /dev/(u)random
sudo -s; /dev/(u)random









share|improve this question




















  • 1




    Please notice that these commands should be used only, when you really need high quality random data, typically in order to create good passwords. Otherwise there are more light-weight alternatives, for example the shell environment 'variable' RANDOM to create random positive integer numbers: echo $RANDOM, and the program shuf to generate random permutations, for example play in random order from a playlist.
    – sudodus
    Apr 18 '18 at 20:31
















24












24








24


7





How can I use /dev/(u)random on Ubuntu or any *nix sistems?



I tried this but it says permission denied.

Note : I also tried as root.



/dev/(u)random
sudo /dev/(u)random
sudo -s; /dev/(u)random









share|improve this question















How can I use /dev/(u)random on Ubuntu or any *nix sistems?



I tried this but it says permission denied.

Note : I also tried as root.



/dev/(u)random
sudo /dev/(u)random
sudo -s; /dev/(u)random






kernel bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 10 '15 at 4:34









Volker Siegel

8,91043349




8,91043349










asked Sep 23 '12 at 19:26









Caner Korkmaz

123116




123116








  • 1




    Please notice that these commands should be used only, when you really need high quality random data, typically in order to create good passwords. Otherwise there are more light-weight alternatives, for example the shell environment 'variable' RANDOM to create random positive integer numbers: echo $RANDOM, and the program shuf to generate random permutations, for example play in random order from a playlist.
    – sudodus
    Apr 18 '18 at 20:31
















  • 1




    Please notice that these commands should be used only, when you really need high quality random data, typically in order to create good passwords. Otherwise there are more light-weight alternatives, for example the shell environment 'variable' RANDOM to create random positive integer numbers: echo $RANDOM, and the program shuf to generate random permutations, for example play in random order from a playlist.
    – sudodus
    Apr 18 '18 at 20:31










1




1




Please notice that these commands should be used only, when you really need high quality random data, typically in order to create good passwords. Otherwise there are more light-weight alternatives, for example the shell environment 'variable' RANDOM to create random positive integer numbers: echo $RANDOM, and the program shuf to generate random permutations, for example play in random order from a playlist.
– sudodus
Apr 18 '18 at 20:31






Please notice that these commands should be used only, when you really need high quality random data, typically in order to create good passwords. Otherwise there are more light-weight alternatives, for example the shell environment 'variable' RANDOM to create random positive integer numbers: echo $RANDOM, and the program shuf to generate random permutations, for example play in random order from a playlist.
– sudodus
Apr 18 '18 at 20:31












4 Answers
4






active

oldest

votes


















45














It's a file like device, so you can do things like cat it or copy from it. For instance:



dd if=/dev/urandom of=~/urandom_test count=4 bs=1024


Creates a file containing 4K of random bytes.



cat /dev/urandom > ~/urandom_test2 


Will continue to write random bytes to that file until you hit Ctrl-C. Don't do this on a low performing system...



head -30 /dev/urandom > ~/urandom_test3


Will write 30 lines of random bytes






share|improve this answer



















  • 1




    Feel free to upvote then!
    – aychedee
    Sep 23 '12 at 19:36






  • 4




    I would if my rep > 15
    – Caner Korkmaz
    Sep 23 '12 at 19:38






  • 1




    Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
    – Caner Korkmaz
    Sep 23 '12 at 19:44










  • Ah, true. I'll change my second example.
    – aychedee
    Sep 23 '12 at 19:50






  • 1




    Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
    – aychedee
    May 11 '15 at 12:37



















9














Get random bytes



If you need a certain number of random bytes, read that number of bytes from /dev/urandom.

It is a "special file" that is made to be like a file to read random numbers from.



Using cat to read from /dev/urandom is a bad idea, because it will try to read /dev/urandom to the end - but it does not end.



You can use head. But take care to read by byte, not by line - because lines would be randomly separated by random newline bytes.



So, to read 30 random bytes into a file random.bytes, use:



head -c 30 /dev/urandom > random.bytes


You can read from it as a normal user.



Leave alone /dev/random



Normally, you want to use /dev/urandom, not /dev/random.



The problem is that /dev/random is hard to use in the right way - and easy to use in a wrong way. Using it wrong works at first, but creates strange - even random - performance problems later. Sometimes.



When you use /dev/urandom, it makes use of /dev/random internally, taking care of the tricky parts.






share|improve this answer





























    1














    If you want to just read it with recognized numbers you can do



    od -d /dev/random





    share|improve this answer





























      0














      I personally use this for generating tokens:



      dd if=/dev/urandom  count=1 bs=128 | sha512sum





      share|improve this answer





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f192203%2fhow-to-use-dev-urandom%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        45














        It's a file like device, so you can do things like cat it or copy from it. For instance:



        dd if=/dev/urandom of=~/urandom_test count=4 bs=1024


        Creates a file containing 4K of random bytes.



        cat /dev/urandom > ~/urandom_test2 


        Will continue to write random bytes to that file until you hit Ctrl-C. Don't do this on a low performing system...



        head -30 /dev/urandom > ~/urandom_test3


        Will write 30 lines of random bytes






        share|improve this answer



















        • 1




          Feel free to upvote then!
          – aychedee
          Sep 23 '12 at 19:36






        • 4




          I would if my rep > 15
          – Caner Korkmaz
          Sep 23 '12 at 19:38






        • 1




          Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
          – Caner Korkmaz
          Sep 23 '12 at 19:44










        • Ah, true. I'll change my second example.
          – aychedee
          Sep 23 '12 at 19:50






        • 1




          Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
          – aychedee
          May 11 '15 at 12:37
















        45














        It's a file like device, so you can do things like cat it or copy from it. For instance:



        dd if=/dev/urandom of=~/urandom_test count=4 bs=1024


        Creates a file containing 4K of random bytes.



        cat /dev/urandom > ~/urandom_test2 


        Will continue to write random bytes to that file until you hit Ctrl-C. Don't do this on a low performing system...



        head -30 /dev/urandom > ~/urandom_test3


        Will write 30 lines of random bytes






        share|improve this answer



















        • 1




          Feel free to upvote then!
          – aychedee
          Sep 23 '12 at 19:36






        • 4




          I would if my rep > 15
          – Caner Korkmaz
          Sep 23 '12 at 19:38






        • 1




          Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
          – Caner Korkmaz
          Sep 23 '12 at 19:44










        • Ah, true. I'll change my second example.
          – aychedee
          Sep 23 '12 at 19:50






        • 1




          Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
          – aychedee
          May 11 '15 at 12:37














        45












        45








        45






        It's a file like device, so you can do things like cat it or copy from it. For instance:



        dd if=/dev/urandom of=~/urandom_test count=4 bs=1024


        Creates a file containing 4K of random bytes.



        cat /dev/urandom > ~/urandom_test2 


        Will continue to write random bytes to that file until you hit Ctrl-C. Don't do this on a low performing system...



        head -30 /dev/urandom > ~/urandom_test3


        Will write 30 lines of random bytes






        share|improve this answer














        It's a file like device, so you can do things like cat it or copy from it. For instance:



        dd if=/dev/urandom of=~/urandom_test count=4 bs=1024


        Creates a file containing 4K of random bytes.



        cat /dev/urandom > ~/urandom_test2 


        Will continue to write random bytes to that file until you hit Ctrl-C. Don't do this on a low performing system...



        head -30 /dev/urandom > ~/urandom_test3


        Will write 30 lines of random bytes







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 23 '12 at 19:52

























        answered Sep 23 '12 at 19:31









        aychedee

        4,87731513




        4,87731513








        • 1




          Feel free to upvote then!
          – aychedee
          Sep 23 '12 at 19:36






        • 4




          I would if my rep > 15
          – Caner Korkmaz
          Sep 23 '12 at 19:38






        • 1




          Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
          – Caner Korkmaz
          Sep 23 '12 at 19:44










        • Ah, true. I'll change my second example.
          – aychedee
          Sep 23 '12 at 19:50






        • 1




          Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
          – aychedee
          May 11 '15 at 12:37














        • 1




          Feel free to upvote then!
          – aychedee
          Sep 23 '12 at 19:36






        • 4




          I would if my rep > 15
          – Caner Korkmaz
          Sep 23 '12 at 19:38






        • 1




          Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
          – Caner Korkmaz
          Sep 23 '12 at 19:44










        • Ah, true. I'll change my second example.
          – aychedee
          Sep 23 '12 at 19:50






        • 1




          Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
          – aychedee
          May 11 '15 at 12:37








        1




        1




        Feel free to upvote then!
        – aychedee
        Sep 23 '12 at 19:36




        Feel free to upvote then!
        – aychedee
        Sep 23 '12 at 19:36




        4




        4




        I would if my rep > 15
        – Caner Korkmaz
        Sep 23 '12 at 19:38




        I would if my rep > 15
        – Caner Korkmaz
        Sep 23 '12 at 19:38




        1




        1




        Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
        – Caner Korkmaz
        Sep 23 '12 at 19:44




        Note : Don't do cat /dev/urandom > ~/urandom_test2 on low-performance systems -> that freezes the system
        – Caner Korkmaz
        Sep 23 '12 at 19:44












        Ah, true. I'll change my second example.
        – aychedee
        Sep 23 '12 at 19:50




        Ah, true. I'll change my second example.
        – aychedee
        Sep 23 '12 at 19:50




        1




        1




        Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
        – aychedee
        May 11 '15 at 12:37




        Well.. that really depends on your definition of a line. My definition is bytes terminated by a n. What's yours? head -30 /dev/urandom will give you 30 lines of random bytes. The length of those lines will certainly be random. Try running wc -l on your output file if you aren't convinced.
        – aychedee
        May 11 '15 at 12:37













        9














        Get random bytes



        If you need a certain number of random bytes, read that number of bytes from /dev/urandom.

        It is a "special file" that is made to be like a file to read random numbers from.



        Using cat to read from /dev/urandom is a bad idea, because it will try to read /dev/urandom to the end - but it does not end.



        You can use head. But take care to read by byte, not by line - because lines would be randomly separated by random newline bytes.



        So, to read 30 random bytes into a file random.bytes, use:



        head -c 30 /dev/urandom > random.bytes


        You can read from it as a normal user.



        Leave alone /dev/random



        Normally, you want to use /dev/urandom, not /dev/random.



        The problem is that /dev/random is hard to use in the right way - and easy to use in a wrong way. Using it wrong works at first, but creates strange - even random - performance problems later. Sometimes.



        When you use /dev/urandom, it makes use of /dev/random internally, taking care of the tricky parts.






        share|improve this answer


























          9














          Get random bytes



          If you need a certain number of random bytes, read that number of bytes from /dev/urandom.

          It is a "special file" that is made to be like a file to read random numbers from.



          Using cat to read from /dev/urandom is a bad idea, because it will try to read /dev/urandom to the end - but it does not end.



          You can use head. But take care to read by byte, not by line - because lines would be randomly separated by random newline bytes.



          So, to read 30 random bytes into a file random.bytes, use:



          head -c 30 /dev/urandom > random.bytes


          You can read from it as a normal user.



          Leave alone /dev/random



          Normally, you want to use /dev/urandom, not /dev/random.



          The problem is that /dev/random is hard to use in the right way - and easy to use in a wrong way. Using it wrong works at first, but creates strange - even random - performance problems later. Sometimes.



          When you use /dev/urandom, it makes use of /dev/random internally, taking care of the tricky parts.






          share|improve this answer
























            9












            9








            9






            Get random bytes



            If you need a certain number of random bytes, read that number of bytes from /dev/urandom.

            It is a "special file" that is made to be like a file to read random numbers from.



            Using cat to read from /dev/urandom is a bad idea, because it will try to read /dev/urandom to the end - but it does not end.



            You can use head. But take care to read by byte, not by line - because lines would be randomly separated by random newline bytes.



            So, to read 30 random bytes into a file random.bytes, use:



            head -c 30 /dev/urandom > random.bytes


            You can read from it as a normal user.



            Leave alone /dev/random



            Normally, you want to use /dev/urandom, not /dev/random.



            The problem is that /dev/random is hard to use in the right way - and easy to use in a wrong way. Using it wrong works at first, but creates strange - even random - performance problems later. Sometimes.



            When you use /dev/urandom, it makes use of /dev/random internally, taking care of the tricky parts.






            share|improve this answer












            Get random bytes



            If you need a certain number of random bytes, read that number of bytes from /dev/urandom.

            It is a "special file" that is made to be like a file to read random numbers from.



            Using cat to read from /dev/urandom is a bad idea, because it will try to read /dev/urandom to the end - but it does not end.



            You can use head. But take care to read by byte, not by line - because lines would be randomly separated by random newline bytes.



            So, to read 30 random bytes into a file random.bytes, use:



            head -c 30 /dev/urandom > random.bytes


            You can read from it as a normal user.



            Leave alone /dev/random



            Normally, you want to use /dev/urandom, not /dev/random.



            The problem is that /dev/random is hard to use in the right way - and easy to use in a wrong way. Using it wrong works at first, but creates strange - even random - performance problems later. Sometimes.



            When you use /dev/urandom, it makes use of /dev/random internally, taking care of the tricky parts.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 10 '15 at 4:59









            Volker Siegel

            8,91043349




            8,91043349























                1














                If you want to just read it with recognized numbers you can do



                od -d /dev/random





                share|improve this answer


























                  1














                  If you want to just read it with recognized numbers you can do



                  od -d /dev/random





                  share|improve this answer
























                    1












                    1








                    1






                    If you want to just read it with recognized numbers you can do



                    od -d /dev/random





                    share|improve this answer












                    If you want to just read it with recognized numbers you can do



                    od -d /dev/random






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 18 '18 at 20:15









                    Seraf

                    1313




                    1313























                        0














                        I personally use this for generating tokens:



                        dd if=/dev/urandom  count=1 bs=128 | sha512sum





                        share|improve this answer


























                          0














                          I personally use this for generating tokens:



                          dd if=/dev/urandom  count=1 bs=128 | sha512sum





                          share|improve this answer
























                            0












                            0








                            0






                            I personally use this for generating tokens:



                            dd if=/dev/urandom  count=1 bs=128 | sha512sum





                            share|improve this answer












                            I personally use this for generating tokens:



                            dd if=/dev/urandom  count=1 bs=128 | sha512sum






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 28 '18 at 0:54









                            Farsheed

                            1615




                            1615






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f192203%2fhow-to-use-dev-urandom%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Category:香港粉麵

                                List *all* the tuples!

                                Channel [V]