shell script 파일 암호화 프로그램 shc 사용법
안녕하세요.
오늘은 shell script 파일을 암호화하는 프로그램의 사용법을 소개드리려고 합니다.
0. 필요성
궁국적으로 이 shc 프로그램을 사용하려는 이유는 일전에 만들어둔 Database backup shell script에 DB 암호가 명시되어 있어서 해당 파일을 암호화 해두기 위함입니다.
mysql backup sheell script는 아래 링크로 가시면 작성법과 상세한 설명을 보실 수 있습니다.
2020/07/03 - [Database/mariaDB administrator] - mysql 백업 shell script crontab 예제
mysql 백업 shell script crontab 예제
mysql 백업 shell script crontab 예제 안녕하세요. mysql 백업을 리눅스 bash shell script로 작성하여 crontab에 등록하여 주기적으로 백업이 되고, 오래된 백업 자료를 삭제하는 것 까지 수행하는 script 예..
stricky.tistory.com
1. 재료 준비
우선, 바로 backup shell script에 적용을 할 수 없으니 test.sh를 하나 만들어 줍니다.
#!/bin/bash
for backup_database in $(cat /data/mysql_backup/shell_script/ulex15_db_backup_databases.txt);
do
echo `date +"%Y-%m-%d %H:%M:%S"`" <<<"$backup_database" backup shell script start!>>>"
done
위와 같이 test.sh을 만들고, 이 shell script가 잘 실행되는지 확인합니다.
./test.sh
잘 실행이 되는 걸 확인했습니다.
재료는 준비가 되었습니다.
2. 프로그램 다운로드
아래 링크로 가서 shell script 파일 암호화 프로그램인 shc를 다운로드합니다.
위 페이지에 접속하면 아래와 같은 화면이 나올 겁니다.
음.. 이분이 이걸 만드셨나 봅니다. 스페인 분이시네요..ㅎㅎ
빨간색 박스로 표시한 부분을 눌러서 다운로드하여, 해당 파일을 서버로 옮겨줍니다.
3. 설치
파일을 옮긴 뒤 아래와 같이 압축을 풀어줍니다.
tar xvfz shc-3.8.9b.gz
명령어를 실행하면 아래와 같이 압축이 풀립니다.
$ tar xvfz shc-3.8.9b.gz
shc-3.8.9b/CHANGES
shc-3.8.9b/Copying
shc-3.8.9b/match
shc-3.8.9b/pru.sh
shc-3.8.9b/shc-3.8.9b.c
shc-3.8.9b/shc.c
shc-3.8.9b/shc.1
shc-3.8.9b/shc.README
shc-3.8.9b/shc.html
shc-3.8.9b/test.bash
shc-3.8.9b/test.csh
shc-3.8.9b/test.ksh
shc-3.8.9b/makefile
shc-3.8.9b/testit
폴더가 생성된 것을 확인하고 폴더내 파일이 잘 생성 된것을 확인합니다.
$ ll
total 24
drwxrwxr-x 3 ulex ulex 45 Jul 6 10:07 ./
drwxr-xr-x 5 ulex ulex 76 Jul 3 17:58 ../
drwxrwxr-x 2 ulex ulex 222 Jul 6 10:07 shc-3.8.9b/
-rw-rw-r-- 1 ulex ulex 20687 Jul 3 17:59 shc-3.8.9b.gz
$ cd shc-3.8.9b/
$ ll
total 96
drwxrwxr-x 2 ulex ulex 222 Jul 6 10:07 ./
drwxrwxr-x 3 ulex ulex 45 Jul 6 10:07 ../
-rw-r----- 1 ulex ulex 3947 Sep 8 2015 CHANGES
-rw-r----- 1 ulex ulex 17982 May 10 1996 Copying
-rw-r----- 1 ulex ulex 2027 Sep 8 2015 makefile
-rwxr-x--- 1 ulex ulex 336 Feb 22 2003 match*
-rwxr-x--- 1 ulex ulex 155 Jun 20 2003 pru.sh*
-rw-r----- 1 ulex ulex 3136 Jul 9 2004 shc.1
-rw-r----- 1 ulex ulex 24893 Sep 8 2015 shc-3.8.9b.c
lrwxrwxrwx 1 ulex ulex 12 Sep 8 2015 shc.c -> shc-3.8.9b.c
-rw-r----- 1 ulex ulex 4558 Jul 9 2004 shc.html
-rw-r----- 1 ulex ulex 1544 Jun 20 2003 shc.README
-rwxr-x--- 1 ulex ulex 138 Nov 13 2004 test.bash*
-rwxr-x--- 1 ulex ulex 52 Jun 20 2003 test.csh*
-rwxr-x--- 1 ulex ulex 67 Sep 8 2015 testit*
-rwxr-x--- 1 ulex ulex 142 Jan 18 2008 test.ksh*
이젠 폴더에서 shc 프로그램 설치를 진행합니다.
$ make install
*** Installing shc and shc.1 on /usr/local
*** ¿Do you want to continue? y
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/
4. 명령어 실행
이젠 설치가 다 되었으면 명령어를 통해서 shell script를 암호화해줍니다.
$ shc -f test.sh
# "test.sh.x"라는 바이너리 파일이 생성 됩니다.
그리고 나면 shell file을 실행해줍니다.
./script.sh.x
5. 기타 참고 사항
- "shc" 명령어는 스크립트에 대한 C 소스 코드를 생성합니다.
- binary로 파일이 생성되므로 "./파일명" 형태로 실행하여야 합니다.
- 생성된 스크립트 파일은 이름을 변경해도 무관합니다.
6. 추가 명령어
이외 추가 명령어들이 아래와 같이 있습니다. 사용하실 때 참고하시기 바랍니다.
-e date
만료일을 지정합니다. (dd/mm/yyyy format)
-m message
만기 시 메시지를 출력합니다.
-f script_name
컴파일할 스크립트 파일을 지정합니다.
감사합니다!!
by.sTricky
'LINUX' 카테고리의 다른 글
[centos]sudo is not in the sudoers file. this incident will be reported 해결방법 (0) | 2020.08.27 |
---|---|
우분투 /var/lib/dpkg/lock-frontend 잠금 파일을 얻을 수 없습니다. 해결 방법 feat.apt-get (5) | 2020.03.04 |
linux core dump file path 리눅스 코어 덤프 파일 위치 확인 feat.사이즈 설정 (0) | 2020.02.21 |
파워쉘을 이용해서 윈도우 텍스트 파일 utf8 인코딩 변경 하기 feat.Get-Content, Set-Content -Encoding (3) | 2020.02.14 |
[linux] vi/vim 명령어 총 정리 끝판왕!! (0) | 2020.01.30 |