Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft post generate-password-cli #40

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
69 changes: 69 additions & 0 deletions _posts/2024-11-09-generate-password-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
layout: post
title: Generate password with command line in Linux or macOS
date: 2024-11-09 16:16:00-0700
description: If you usually work with command line in Linux or macOS, you can use it to generate password without installing any additional application.
tags: cli password-generating command-line linux macos
categories: utilities
giscus_comments: true
related_posts: false
toc:
beginning: true
---

Most websites or application require a strong password that contains a mix of letters, numbers and special characters. And to make it more secure, it should be unique and randomly generated for each account.
If you are using Linux or macOS and usually work with command line, you can use it to generate without installing any additional application.

### Using /dev/urandom or /dev/random

This is my favorite way to generate password because `/dev/urandom` and `/dev/random` are available in most Unix-like operating systems.

```sh
< /dev/urandom tr -dc '[:graph:]' | head -c32; echo
```

This command will create a random password with printable character, length is 32.

In case that alphabet & numeric character, use `alnum` instead of `graph`.

For more information, see `tr` [manpage](https://linuxcommand.org/lc3_man_pages/tr1.html)

With macOS, an error occur when run above command because of UTF-8. Just add LC_ALL=C as below:

```sh
< /dev/urandom LC_ALL=C tr -dc '[:graph:]' | head -c32; echo
```

#### Random

/dev/random takes the random values from the entropy pool. If the entropy pool is empty, it will be blocked reading.

#### URandom (Unlimited Random)

/dev/urandom is similar to /dev/random but in case that entropy pool is empty, it generate value using hashing argorithm such as: SHA, MD5, ...

#### In term of security

Because of high-quality randomness of /dev/random, it's suitable for a password or a task focus on security.

### Using openssl

```sh
openssl rand -base64 32
```

This command can only generate a base64 string password.

### Using date and hashing

```sh
date | md5
```

It similar to openssl command, but it's not really random like openssl or /dev/urandom.

### Using gpg

```sh
gpg --gen-random 1 32
```