"Bash 랜덤 패스워드 생성"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 28개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
;random complex password generator
;random complex password generator
;랜덤 패스워드 생성, 복잡한 암호 생성기, 복잡한 무작위 패스워드 생성, 복잡한 패스워드 만들기
;랜덤 패스워드 생성
*때로는 [[복잡한 암호]]를 만들어 내기가 귀찮다. 그래서 Bash와 PHP로 만들어 보았다.
*예제: http://jmnote.com/php/pass_gen.php


==PHP 소스코드==
==base 16==
<source lang='php'>
<syntaxhighlight lang='bash'>
<!DOCTYPE html>
head /dev/urandom | md5sum
<meta charset='UTF-8'>
head /dev/urandom | sha1sum
<title>복잡한 패스워드 생성기</title>
</syntaxhighlight>
<h1>복잡한 패스워드 생성기</h1>
<syntaxhighlight lang='console'>
<p>대문자 2개 + 소문자 2개 + 숫자 2개 + 특수문자 2개</p>
$ head /dev/urandom | md5sum
<?php
295a3aa99c41bbe8cad13c86d1cd3b5b  -
$uppers = str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$ head /dev/urandom | sha1sum
$lowers = str_shuffle('abcdefghijklmnopqrstuvwxyz');
7e8578e965b45bd000439bb36eb40de31b8133b8  -
$numbers = str_shuffle('1234567890');
</syntaxhighlight>
$specials = str_shuffle('!@#$%^&*()');
$complex_password = substr($uppers,-2).substr($lowers,-2).substr($numbers,-2).substr($specials,-2);
$more_complex_password = str_shuffle($complex_password);
echo "복잡한 패스워드: <input type='text' value='$complex_password'><br>";
echo "더 복잡한 패스워드: <input type='text' value='$more_complex_password'><br>";
?>
</source>
*예제: http://jmnote.com/php/pass_gen.php


==Bash 소스 1==
==base 62 (alnum)==
<source lang='bash'>
<syntaxhighlight lang='console'>
UPPERS=`echo 'A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z' | tr ';' '\n' | shuf | xargs | tr -d ' '`
testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:]" | head -c 16; echo
LOWERS=`echo 'a;b;c;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z' | tr ';' '\n' | shuf | xargs | tr -d ' '`
hdjOc1gjcaOGUE2G
NUMBERS=`echo '1;2;3;4;5;6;7;8;9;0' | tr ';' '\n' | shuf | xargs | tr -d ' '`
testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:]" | head -c 32; echo
SPECIALS=`echo '!;@;#;$;%;^;&;*;(;)' | tr ';' '\n' | shuf | xargs | tr -d ' '`
88PUO0LiJNSYhmkxhGQzRTmUlQwNMEWz
COMPLEX_PASSWORD=${UPPERS:0:2}${LOWERS:0:2}${NUMBERS:0:2}${SPECIALS:0:2}
</syntaxhighlight>
echo $COMPLEX_PASSWORD
</source>


;실행예시
==base 64==
<source lang='dos'>
<syntaxhighlight lang='bash'>
[root@jmnote ~]# UPPERS=`echo 'A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z' | tr ';' '\n' | shuf | xargs | tr -d ' '`
base64 /dev/urandom | head -c32
[root@jmnote ~]# LOWERS=`echo 'a;b;c;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z' | tr ';' '\n' | shuf | xargs | tr -d ' '`
base64 /dev/urandom | head -1
[root@jmnote ~]# NUMBERS=`echo '1;2;3;4;5;6;7;8;9;0' | tr ';' '\n' | shuf | xargs | tr -d ' '`
</syntaxhighlight>
[root@jmnote ~]# SPECIALS=`echo '!;@;#;$;%;^;&;*;(;)' | tr ';' '\n' | shuf | xargs | tr -d ' '`
<syntaxhighlight lang='console'>
[root@jmnote ~]# COMPLEX_PASSWORD=${UPPERS:0:2}${LOWERS:0:2}${NUMBERS:0:2}${SPECIALS:0:2}
$ base64 /dev/urandom | head -c32
[root@jmnote ~]# echo $COMPLEX_PASSWORD
M5WB9OTY0fiydZkoBZVhLw07s1O8tRw
KFht37!&
$ base64 /dev/urandom | head -c32
</source>
9+0SO/FD9r+v7YM1o3juS9573hojBxwK
$ base64 /dev/urandom | head -1
g0THG3/uSMumZvREof+Bo99ZZqYtRtDjxsNgAwYuDOt0EsBJZ+vD9LUe3CUefkI1zusKQfvar8EL
</syntaxhighlight>


==Bash 소스 2==
==기타==
<source lang='bash'>
<syntaxhighlight lang='console'>
function randpass() { cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c ${1:-8}; echo; }
testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c 16
randpass
N~#:+?sf}`J8Q)O5
</source>
</syntaxhighlight>
 
<syntaxhighlight lang='console'>
<source lang='dos'>
testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c 32
[root@jmnote ~]# function randpass() { cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c ${1:-8}; echo; }
~MlO~{rMH-Q>~KN}L&f$FzH!PP];&Jl$
[root@jmnote ~]# randpass
</syntaxhighlight>
qUrwPpNx
[root@jmnote ~]# randpass
X]]#z`6H
[root@jmnote ~]# randpass 16
=U8@E3]S{.ooY?y#
</source>


==관리자도 알 수 없는 랜덤 패스워드 지정==
==관리자도 알 수 없는 랜덤 패스워드 지정==
;명령어
{{참고|리눅스 관리자도 알 수 없는 랜덤 패스워드 지정}}
<source lang='bash'>
{{소스헤더|명령어}}
cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c 16 | passwd --stdin 계정명
<syntaxhighlight lang='bash'>
</source>
echo "계정명:$(base64 /dev/urandom | head -1)" | chpasswd
</syntaxhighlight>


;실행예시
{{소스헤더|실행예시}}
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c 16 | passwd --stdin testuser
root@localhost:~$ cat /etc/shadow | grep testuser
Changing password for user testuser.
testuser:$6$ayXX4iHhNIGvybNF$sQJkmLNuIZ/7OX0ctYed2XpnvcUG27XrMSwI//K6pPva0DsW6VlcFXeUlUExO92IWDbtdSSPpEDAVXX1wBU6j0:18786:0:99999:7:::
passwd: all authentication tokens updated successfully.
root@localhost:~$ echo "testuser:$(base64 /dev/urandom | head -1)" | chpasswd
</source>
root@localhost:~$ cat /etc/shadow | grep testuser
testuser:$6$xO5jdedzcPwS8qsC$JopOEbelAiM7FPjBPsXsQkhnS64V1Z9gE1IYjcZyazK8xHNRO8DF.TPDQqE5/pQDqGwwnZYDxbU1WJg4yTTkK/:18786:0:99999:7:::
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[복잡한 패스워드]]
{{z컬럼3|
*[[복잡한 패스워드인지 확인]]
* [[리눅스 tr]]
*[[리눅스 패스워드 변경]]
* [[리눅스 chpasswd]]
*[[랜덤]]
* [[randpass]]
*[[정규식 문자 클래스]]
* [[복잡한 패스워드]]
 
* [[복잡한 패스워드인지 확인]]
==참고 자료==
* [[리눅스 패스워드 변경]]
*http://snoopybox.co.kr/1616
* [[정규식 문자 클래스]]
*http://en.wikipedia.org/wiki/Random_password_generator
}}
*http://eqcode.com/wiki/Generate_password


[[분류: 랜덤]]
[[분류: 랜덤 패스워드]]
[[분류: 패스워드]]
[[분류: Bash]]
[[분류: Bash]]
[[분류: PHP]]
[[분류: /dev/urandom]]

2021년 6월 9일 (수) 02:08 기준 최신판

1 개요[ | ]

random complex password generator
랜덤 패스워드 생성

2 base 16[ | ]

head /dev/urandom | md5sum
head /dev/urandom | sha1sum
$ head /dev/urandom | md5sum
295a3aa99c41bbe8cad13c86d1cd3b5b  -
$ head /dev/urandom | sha1sum
7e8578e965b45bd000439bb36eb40de31b8133b8  -

3 base 62 (alnum)[ | ]

testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:]" | head -c 16; echo
hdjOc1gjcaOGUE2G
testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:]" | head -c 32; echo
88PUO0LiJNSYhmkxhGQzRTmUlQwNMEWz

4 base 64[ | ]

base64 /dev/urandom | head -c32
base64 /dev/urandom | head -1
$ base64 /dev/urandom | head -c32
M5WB9OTY0fiydZkoBZVhLw07s1O8tRw
$ base64 /dev/urandom | head -c32
9+0SO/FD9r+v7YM1o3juS9573hojBxwK
$ base64 /dev/urandom | head -1
g0THG3/uSMumZvREof+Bo99ZZqYtRtDjxsNgAwYuDOt0EsBJZ+vD9LUe3CUefkI1zusKQfvar8EL

5 기타[ | ]

testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c 16
N~#:+?sf}`J8Q)O5
testuser@localhost:~$ cat /dev/urandom | tr -cd "[:alnum:][:graph:]" | head -c 32
~MlO~{rMH-Q>~KN}L&f$FzH!PP];&Jl$

6 관리자도 알 수 없는 랜덤 패스워드 지정[ | ]

명령어
echo "계정명:$(base64 /dev/urandom | head -1)" | chpasswd
실행예시
root@localhost:~$ cat /etc/shadow | grep testuser
testuser:$6$ayXX4iHhNIGvybNF$sQJkmLNuIZ/7OX0ctYed2XpnvcUG27XrMSwI//K6pPva0DsW6VlcFXeUlUExO92IWDbtdSSPpEDAVXX1wBU6j0:18786:0:99999:7:::
root@localhost:~$ echo "testuser:$(base64 /dev/urandom | head -1)" | chpasswd
root@localhost:~$ cat /etc/shadow | grep testuser
testuser:$6$xO5jdedzcPwS8qsC$JopOEbelAiM7FPjBPsXsQkhnS64V1Z9gE1IYjcZyazK8xHNRO8DF.TPDQqE5/pQDqGwwnZYDxbU1WJg4yTTkK/:18786:0:99999:7:::

7 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}