ランダムパスワードを自動生成するコマンド

このエントリーをはてなブックマークに追加
mkpasswd
head -c 8 /dev/random

パスワードを作るときに、キーボードをガチャガチャ押して「rdftgyふじこlp@;」とかやってませんか?
ちゃんとランダムでセキュリティ上安全なパスワードを作りましょう。

mkpasswdを使う

mkpasswd

このコマンドで、ランダムな文字列が生成されます。
もしこのコマンドが使えなかったら、expectパッケージがインストールされていません。
yumでインストールしておきましょう。

# yum install expect

さてこのパスワード、デフォルトでは全9文字(小文字2、大文字2、数字2、特殊文字1)です。
文字数や使用文字の種類は、オプションで細かくカスタマイズすることができます。

例えば、「数字2+アルファベット6で全8文字のパスワード」を作りたい場合は、

# mkpasswd -l 8 -c 6 -d 2 -C 0 -s 0
riwp36jh

となります。
その他オプション一覧

  • -l 数字 … パスワードの長さを指定(デフォルトは9)
  • -d 数字 … パスワードに含める数字の数を指定(デフォルトは2)
  • -c 数字 … パスワードに含めるアルファベット(小文字)の数を指定(デフォルトは2)
  • -C 数字 … パスワードに含めるアルファベット(大文字)の数を指定(デフォルトは2)
  • -s 数字 … パスワードに含める特殊文字(記号など)の数を指定(デフォルトは1)
  • -2 … パスワードが、右手と左手で交互に入力される文字配列となる。(入力時に手元を見られて盗まれる可能性を低くするため)

最後の-2オプションは「へぇ~」という感じですね。

# mkpasswd -l 6 -c 6 -d 0 -C 0 -s 0 -2
yapsng

/dev/random を使う

Linuxが、様々な処理で乱数を必要とする時のために、/dev/random という乱数発生器が存在します。
ここから、headコマンドで8バイトほど取り出して、ランダムな8文字を作り出すことができます。

# head -c 6 /dev/random | uuencode -m –
begin-base64 644 –
FgGWD/8x
====

1行目と2行目はヘッダとフッタなので無視して構いませんが、気にる人や自動処理するときなどのために、sedに渡して削除して出力することもできます。

# head -c 6 /dev/random | uuencode -m – | sed -n ‘2s/=*$//;2p’
+VTO0nVo
-bash: uuencode: command not found

「uuencodeがない」と表示される場合は、sharutilsパッケージをインストールします。

[root@myserver ]# yum install uuencode                                                                                                                                                
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
 * atomic: www2.atomicorp.com
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
atomic                                                                                                                                                                | 1.9 kB     00:00     
base                                                                                                                                                                  | 1.1 kB     00:00     
extras                                                                                                                                                                | 2.1 kB     00:00     
updates                                                                                                                                                               | 1.9 kB     00:00     
Setting up Install Process
No package uuencode available.
Nothing to do
[root@rad-xen-vweb10 ~]# yum install sharutils
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
 * atomic: www2.atomicorp.com
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package sharutils.x86_64 0:4.6.1-2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================
 Package                                         Arch                                         Version                                       Repository                                  Size
=============================================================================================================================================================================================
Installing:
 sharutils                                       x86_64                                       4.6.1-2                                       base                                       203 k

Transaction Summary
=============================================================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 203 k
Is this ok [y/N]: y
Downloading Packages:
sharutils-4.6.1-2.x86_64.rpm                                                                                                                                          | 203 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : sharutils                                                                                                                                                             1/1 

Installed:
  sharutils.x86_64 0:4.6.1-2                                                                                                                                                                 

Complete!

ランダムパスワードを自動生成するコマンド」への44件のフィードバック

  1. our website

    I simply want to say I am new to blogging and site-building and actually loved this web blog. Likely I’m planning to bookmark your blog . You definitely have great writings. Many thanks for sharing with us your web site.

    返信
  2. Mary Mcburnie

    My wife and i got quite excited when Edward managed to deal with his investigations from the precious recommendations he had when using the web site. It is now and again perplexing to simply choose to be giving out secrets and techniques which usually most people have been making money from. And we realize we’ve got the website owner to appreciate for that. All of the explanations you made, the simple web site navigation, the friendships you can make it easier to instill – it’s got all awesome, and it’s leading our son in addition to the family know that the theme is satisfying, and that is exceedingly fundamental. Many thanks for all! visit my site here – alternative medicine institute

    返信
  3. Tristan

    Just how does one earn money from blog sites? Exactly how does one begin it or set about it? Exists a particular method to do it? Simply exactly how does one earn money from blogs to begin with? Where does one get started in this? Do you have to market and utilize your credit card? Are there any type of specific sort of policies you need to comply with? Do you need to set the blog site up yourself or are there ones that aid you establish it up? Exactly how do you obtain advertisers on your blog? Are people minimal to the number of blogs online? Just how commonly do you make money?. Many thanks for the assistance!.

    返信
  4. Todd Snively

    I would like to thnkx for the efforts you have put in writing this blog. I am hoping the same high-grade web site post from you in the upcoming as well. In fact your creative writing abilities has inspired me to get my own website now. Actually the blogging is spreading its wings fast. Your write up is a great example of it.

    返信
  5. Chet Rohwer

    This is the perfect blog for anyone who would like to understand this topic. You know a whole lot its almost hard to argue with you (not that I actually would want to…HaHa). You certainly put a brand new spin on a subject that has been written about for years. Wonderful stuff, just great.

    返信
  6. Love Irrigation

    When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and now each time a comment is added I get 4 emails with the same comment. Perhaps there is a way you are able to remove me from that service? Appreciate it.

    返信
  7. Arturo Turck

    Howdy here, just turned familiar with your article through The Big G, and have found that it’s pretty informative. I will appreciate should you decide keep up this idea.

    返信
  8. Jong Vaske

    Right here is the perfect site for anyone who really wants to find out about this topic. You realize a whole lot its almost tough to argue with you (not that I really will need to…HaHa). You definitely put a new spin on a subject which has been written about for a long time. Excellent stuff, just excellent.

    返信
  9. Tractor Workshop Manuals

    I would like to thnkx for the efforts you have put in writing this blog. I’m hoping the same high-grade website post from you in the upcoming also. Actually your creative writing skills has inspired me to get my own site now. Actually the blogging is spreading its wings rapidly. Your write up is a good example of it.

    返信
  10. Dottie Lemans

    It happens to be ideal day to generate some goals for the future. I have digested this piece of writing and if I can possibly, I desire to recommend you couple of unique recommendation.

    返信
  11. original site

    I just want to mention I am newbie to blogging and site-building and definitely savored your blog site. More than likely I’m going to bookmark your site . You amazingly have remarkable writings. With thanks for sharing your blog.

    返信
  12. https://realizaredesignprofesional.blogspot.com/

    Hey there! I simply wish to give you a huge thumbs up for the excellent information you
    have here on this post. I will be coming back to your web site
    for more soon.

    返信
  13. hotmail iniciar sesion

    I blog frequently and I genuinely appreciate your content. This article has really peaked my interest. I will take a note of your blog and keep checking for new details about once a week. I opted in for your RSS feed as well.

    返信
  14. Nylander Fashion House

    An intriguing discussion is worth comment. I believe that you need to write more on this subject, it might not be a taboo matter but generally people do not discuss such issues. To the next! Best wishes.

    返信
  15. Metroclick

    It can be almost extremely difficult to come across well-informed users on this matter, still you seem like you fully understand exactly what you’re writing on! Regards

    返信
  16. The Path of Wisdom

    May I simply say what a relief to find someone who really knows what they are talking about over the internet. You certainly realize how to bring an issue to light and make it important. More and more people must read this and understand this side of your story. I was surprised that you aren’t more popular because you certainly have the gift.

    返信
  17. Fastandy

    This is a really good tip especially to those fresh to the blogosphere. Short but very precise info… Appreciate your sharing this one. A must read article.

    返信
  18. Elle Blonde

    Hello, I think your blog might be having web browser compatibility problems. Whenever I look at your web site in Safari, it looks fine however, when opening in IE, it has some overlapping issues. I merely wanted to provide you with a quick heads up! Apart from that, fantastic site.

    返信
  19. Davis Crye

    It happens to be most suitable time to put together some intentions for the long-run. I have browsed this document and if I could, I desire to suggest to you you number of important proposal.

    返信
  20. Aconda

    An interesting discussion is worth comment. There’s no doubt that that you need to publish more on this topic, it might not be a taboo matter but usually people don’t speak about such topics. To the next! Kind regards!

    返信
  21. shop wise

    Your style is really unique compared to other people I have read stuff from. Many thanks for posting when you have the opportunity, Guess I’ll just bookmark this web site.

    返信
  22. Avaluos en Cancun

    I’m impressed, I must say. Seldom do I encounter a blog that’s both equally educative and amusing, and let me tell you, you have hit the nail on the head. The issue is something which not enough men and women are speaking intelligently about. Now i’m very happy that I found this in my search for something concerning this.

    返信
  23. Kratom Sulawesi

    I would like to thank you for the efforts you have put in penning this website. I’m hoping to view the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has encouraged me to get my own website now ;)

    返信
  24. cbd oil

    That is a very good tip particularly to those fresh to the blogosphere. Brief but very precise information… Appreciate your sharing this one. A must read post!

    返信

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>