{
    "mode": "man",
    "parameter": "mcookie",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/mcookie/1/json",
    "generated": "2026-06-16T05:02:58Z",
    "synopsis": "mcookie [options]",
    "sections": {
        "NAME": {
            "content": "mcookie - generate magic cookies for xauth\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "mcookie [options]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "mcookie generates a 128-bit random hexadecimal number for use with the X authority system.\nTypical usage:\n\nxauth add :0 . mcookie\n\nThe \"random\" number generated is actually the MD5 message digest of random information coming\nfrom one of the sources getrandom(2) system call, /dev/urandom, /dev/random, or the libc\npseudo-random functions, in this preference order. See also the option --file.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-f --file",
                    "content": "Use this file as an additional source of randomness (for example /dev/urandom). When file\nis '-', characters are read from standard input.\n",
                    "flag": "-f",
                    "long": "--file"
                },
                {
                    "name": "-m --max-size",
                    "content": "Read from file only this number of bytes. This option is meant to be used when reading\nadditional randomness from a file or device.\n\nThe number argument may be followed by the multiplicative suffixes KiB=1024,\nMiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the \"iB\" is optional, e.g.,\n\"K\" has the same meaning as \"KiB\") or the suffixes KB=1000, MB=1000*1000, and so on for\nGB, TB, PB, EB, ZB and YB.\n",
                    "flag": "-m",
                    "long": "--max-size"
                },
                {
                    "name": "-v --verbose",
                    "content": "Inform where randomness originated, with amount of entropy read from each source.\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-V --version",
                    "content": "Display version information and exit.\n",
                    "flag": "-V",
                    "long": "--version"
                },
                {
                    "name": "-h --help",
                    "content": "Display help text and exit.\n",
                    "flag": "-h",
                    "long": "--help"
                }
            ]
        },
        "FILES": {
            "content": "/dev/urandom\n\n/dev/random\n",
            "subsections": []
        },
        "BUGS": {
            "content": "It is assumed that none of the randomness sources will block.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "md5sum(1), X(7), xauth(1), rand(3)\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "For bug reports, use the issue tracker at https://github.com/karelzak/util-linux/issues.\n",
            "subsections": []
        },
        "AVAILABILITY": {
            "content": "The mcookie command is part of the util-linux package which can be downloaded from Linux\nKernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.\n\n\n\nutil-linux 2.37.2                            2021-06-02                                   MCOOKIE(1)",
            "subsections": []
        }
    },
    "summary": "mcookie - generate magic cookies for xauth",
    "flags": [
        {
            "flag": "-f",
            "long": "--file",
            "arg": null,
            "description": "Use this file as an additional source of randomness (for example /dev/urandom). When file is '-', characters are read from standard input."
        },
        {
            "flag": "-m",
            "long": "--max-size",
            "arg": null,
            "description": "Read from file only this number of bytes. This option is meant to be used when reading additional randomness from a file or device. The number argument may be followed by the multiplicative suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the \"iB\" is optional, e.g., \"K\" has the same meaning as \"KiB\") or the suffixes KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "Inform where randomness originated, with amount of entropy read from each source."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Display version information and exit."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "Display help text and exit."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "md5sum",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/md5sum/1/json"
        },
        {
            "name": "X",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/X/7/json"
        },
        {
            "name": "xauth",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/xauth/1/json"
        },
        {
            "name": "rand",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/rand/3/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Generate random 128-bit hexadecimal numbers.",
        "examples": [
            {
                "description": "Generate a random number",
                "command": "mcookie"
            },
            {
                "description": "Generate a random number, using the contents of a file as a seed for the randomness",
                "command": "mcookie {{-f|--file}} {{path/to/file}}"
            },
            {
                "description": "Generate a random number, using a specific number of bytes from a file as a seed for the randomness",
                "command": "mcookie {{-f|--file}} {{path/to/file}} {{-m|--max-size}} {{number_of_bytes}}"
            },
            {
                "description": "Print the details of the randomness used, such as the origin and seed for each source",
                "command": "mcookie {{-v|--verbose}}"
            }
        ]
    }
}