Nginx - HTTPS and Certificate SSL

Nginx를 HTTPS를 사용할 수 있도록 사설 인증서와 그리고 공인 인증서를 이용해 SSL을 활성화 하는 과정을 정리했다.

Nginx 설치와 서버, 프락시 등의 사용 방법에 대해서는 Nginx on Ubuntu/Debian 문서를 참조한다.

자세히 보기

Ubuntu/Debian Basic Security settings

리눅스 시스템을 설치후 기본적인 보안 설정과 도구를 사용하는 과정을 정리했다.

  • firewall 과 sshd
  • rootkit
  • fail2ban

Firewall과 ssh 보안 구성

사용자 로그인에 제약을 두고, 원격 접속에 대해서 방화벽과 sshd 보안을 강화한다.

자세히 보기

UFW Firewall on Ubuntu/Debian

일반적인 리눅스 배포본의 방화벽인 ufw` 를 사용해서 리눅스에 방화벽을 구축하는 방법을 기술하고 있다.

  • 2019-12-10: 정리
  • 2017-09-10: Log, export 추가서
    {:.right-history}

여기서 사용, 테스트한 리눅스 배포본은 Ubuntu 14.04, 15.04, 16.04 계열에서 동작하리라 믿는다. 실제 Raspbian Weezy, Jessie, Armbian Ubuntu 16.04, Debian Jessie 에서 사용중이다.

자세히 보기

Linux LVM2

2023-10 add pysical volume to vg
2018-09-19 when umount, device busy!
2018-06-23 mount 명령
{: history-right}

LVM2 를 사용해 물리 disk를 논리 disk로 분할/합병/관리 하는 과정을 조금 정리한 것이다.

LVM2

SBC보드인 Odorid C2에 USB Memory를 사용해서 리눅스의 LVM을 이용하고 있다. 여기서는 LVM 설정에 대해서만 다루고 있다.

Single board computer 종류의 보드는 주 디스크로 SD Card, eMMC 를 사용하고, USB 메모리 등은 디바이스 장치로 /dev/sd* 이름으로 접근할 수 있다.

자세히 보기

Nginx - Install, WebDAV, Proxy on Ubuntu/Debian

nginx를 사용해서 일반 웹 서비스, SSL, WebDav 서비스와 다른 외부 웹 서비스와 연동하는 설정을 해보자.

  • 여기서 node.js 애플리케이션을 연동한다.

## Nginx 설치와 구성

우분투/데비안 계열에서 apt-get install 명령으로 설치한다.

자세히 보기

Rasbian Wheezy 설치후 작업

upgrade

1
# apt update && apt dist-upgrade && apt upgrade

업그레이드 중

1
The following packages have been kept back:   linux-image-c2

기존 리눅스 이미지를 지우고 업그리이드 중 에러가 나서 이미지 업그레이드가 안되었으므로, 이전 버전 이미지를 찾아 삭제해 주면 다시 업그레이드가 된다.

1
2
3
4
5
6
7
# apt --installed list |grep linux

linux-image-3.14.65-73/unknown,now 20160802 arm64 [installed,automatic]
linux-image-3.14.79-94/unknown,now 20161121 arm64 [installed,automatic]
linux-image-c2/now 73-1 arm64 [installed,upgradable to: 94-1]
linux-libc-dev/xenial-updates,xenial-security,now 4.4.0-51.72 arm64 [installed]
util-linux/xenial-updates,now 2.27.1-6ubuntu3.1 arm64 [installed]

이전 버전 이미지를 지운다. 업그레이드 후 uname 확인

1
2
3
4
5
6
7
8
root@odroid64:~# apt autoremove linux-image-3.14.65-73
...
Preparing to unpack .../linux-image-c2_94-1_arm64.deb ...
Unpacking linux-image-c2 (94-1) over (73-1) ...
Setting up linux-image-c2 (94-1) ...

# uname -a
Linux odroid64 3.14.79-94 #1 SMP PREEMPT Mon Nov 21 17:13:27 BRST 2016 aarch64 aarch64 aarch64 GNU/Linux

설정

hostname

debian 계열에서 hostname을 변경하려면 hostnamectl 을 사용한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo -s
# hostnamectl set-hostname dlp
# show settings
root@debian:~# hostnamectl
Static hostname: dlp
Icon name: computer-vm
Chassis: vm
Machine ID: 5f47b11299ed4689a48a7f78197e452a
Boot ID: bdeed3b6c079405bb45d79eff3e870a5
Virtualization: vmware
Operating System: Debian GNU/Linux 8 (jessie)
Kernel: Linux 3.16.0-4-amd64
Architecture: x86-64

Timezone

CLI에서 설정을 할 수 있다.

1
# dpkg-reconfigure tzdata

timedatectl timedatectl 명령으로

1
2
3
4
5
6
$ timedatectl list-timezones
...
Asia/Seoul
...

$ sudo timedatectl set-timezone Asia/Seoul

혹은 손으로 직접 수정한다면, Timezone/etc/localtime 이라는 바이너리로 저장되므로
명령행에서 지원하는 timezone을 복사할 수 도 있다.

1
$ sudo cp /usr/share/zoneinfo/Europe/London /etc/localtime

기본 에디터 변경

odroid의 ubuntu 16.04는 기본에디터로 joe가 설치되어 있다. vim 으로 변경한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# update-alternatives --config editor
There are 6 choices for the alternative editor (providing /usr/bin/editor).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/joe 70 auto mode
1 /usr/bin/jmacs 50 manual mode
2 /usr/bin/joe 70 manual mode
3 /usr/bin/jpico 50 manual mode
4 /usr/bin/jstar 50 manual mode
5 /usr/bin/rjoe 25 manual mode
6 /usr/bin/vim.tiny 10 manual mode

Press <enter> to keep the current choice[*], or type selection number: 6

apt autocompetion

bash-completion 이 빠져 있으면

1
$ sudo apt install bash-completion

apt-get 명령은 자동완성이 되지만 apt 명령은 안된다면

1
$ sudo apt install --reinstall bash-completion

Dnsutils

dig, nslookup 같은 명령이 있는 패키지.

1
$ sudo apt install dnsutils

디스크

tune2fs

fsck로 마지막 체크한 시간 확인은 tune2fs 명령을 이용

1
2
$sudo tune2fs -l /dev/sdbX | grep Last\ c
Last checked: Sun Dec 13 09:14:22 2015

마운트 횟수

1
2
tune2fs -l /dev/sdbX | grep Mount
Mount count: 157
1
2
tune2fs -l /dev/sdbX | grep Max
Maximum mount count: -1

참조: https://linuxconfig.org/how-to-force-fsck-to-check-filesystem-after-system-reboot-on-linux

fsck

루트 파티션을 강제로 fsck 하게 하려면 루트 파티션에 forcefsck 파일을 생성해 둔다.

1
$sudo touch /forcefsck

forcefsck 파일은 단 한번만 부팅시 루트 파일시스템을 체크한다. 만약 지속적으로 파일 시스템을 체크하도록 하려면 tune2fs 를 사용해서 ‘Maximum mount count’ 파라미터를 사용하도록 한다.

아래 명령은 부팅시마다 루트 파티션을 체크하게 된다.

1
tune2fs -c 10 /dev/sdb1

이렇게 하면 fsck Maxium mount 값을 양의 값으로 지정하게 된다. 그리고 10번째 부팅시 체크하도록 하려면 -c 10 을 준다.

1
tune2fs -c 10 /dev/sdb1

SWAP

swap 파일로 만들려면

1
2
3
4
5
$ sudo dd if=/dev/zero of=/data/swap4G bs=1G count=4
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
1
2
3
sudo mkswap /dev/sda1
sudo swapon /dev/sda1
sudo swapon -s

grc

터미널 컬러 처리

1
2
3
4
grc netstat
grc ping hostname
grc tail /var/log/syslog
grc ps aux

lastb

lastb 명령은 /var/log/wtmp, /var/log/btmp 에 있는 로그인 기록에서 최근 로그인한 모든 목록을 출력한다. 다음은 최근 20개 목록을 출력한다.

1
2
3
4
5
$ sudo lastb -n 20
root ssh:notty 112.85.42.230 Fri Jul 20 17:25 - 17:25 (00:00)
root ssh:notty 112.85.42.230 Fri Jul 20 17:25 - 17:25 (00:00)
oracle ssh:notty 210.182.116.102 Mon Jul 16 23:36 - 23:36 (00:00)
cumulus ssh:notty 36.248.211.16 Mon Jul 16 20:59 - 20:59 (00:00)

실패한 로그인 시도

https://www.guyrutenberg.com/2014/09/26/view-failed-login-attempts-lastb/

-w 로 사용자 이름을 출력하고 첫번째 열만 자른 후 정렬한 후, uniq 명령으로 중복되는 이름을 제거한 후 출력한다.

1
$ sudo lastb -w | cut -d " " -f 1 | sort | uniq | less

이중에서 접속한 IP와 횟수를 출력한다.

1
2
3
4
5
6
7
8
$ sudo lastb -f /var/log/btmp.1 -w -i | awk '{print $3}' | sort | uniq --count | sort -nr | less

[sudo] root의 암호:
2166 112.85.42.156
1945 112.85.42.193
1591 112.85.42.201
1327 112.85.42.230
1146 112.85.42.196

기본 Python 만들기

사용자 파이썬 앨리어스 만들기

사용자 홈 디렉토리에 ~/.bashrc 파일에 앨리어스를 만든다.

1
alias python='/usr/bin/python3.4'

다시 로그인 하거나 .bashrc를 컴파일해서 사용한다.

1
$ . ~/.bashrc

시스템 전체로 파이썬 구성하기

1
2
$ update-alternatives --list python
update-alternatives: error: no alternatives for python

여기서 python2.7과 python3.5 를 update-alternative 로

1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
1
2
$ sudo  update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode

파이썬 관련 대체 프로그램 목록을 보면,

1
2
3
$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.5

삭제를 하려면

1
$sudo update-alternatives --remove python /usr/bin/python2.7

Odroid - Install Linux

2018-07-10: UART 정보 추가
2017-07-24: exFAT 추가
{:.right-history}

Odroid C2 - Install Armbian

{: width=”600”}

[그림. armv8 Odroid C2]
자세히 보기

SD Card 포맷 및 디스크 이미지 사용하기

SBC, PC 등의 머신에서 SD Card 사용에 필요한 사항을 정리했다.

2018-08-30: 전체 내용 편집
2017-10-30: swap 추가, timezone 수정
{:.right-history}


## SD Card 와 디스크 이미지 사용하기

SD Card는 Secure Digital의 약자로 Flash memory(비휘발성) 카드 포맷이다.

자세한 내용은 Wikipedia: SD Card 를 확인하자.

자세히 보기

Cloud Drives 마운트 사용하기

리눅스 ( 아마 Armbian 서버에서 사용하려고 했었던 것 같다?!)에서 Cloud drive를 사용하고자 한다.

Odroid C2 그리고 Orange-pi 시스템에서 사용할, 데스크탑 환경의 Armbian Xenial에서 사용하기 위해 클라우드 드라이브를 사용할 목적으로 사용했었다.

Google Drive

Google drive는 grive 패키지로 제공되고 있다. 최근 (아마 2016년 이후) Google의 REST API가 바뀌어 grive2 패키지를 사용해야 한다. 패키지 제공이 되지 않으면 소스 빌드해서 사용했다.

grive2 소스 기반 설치

Debian/Ubuntu/Linux Mint 에서 다음 라이브러리가 필요하다:

  • yajl 2.x
  • libcurl
  • libstdc++
  • libgcrypt
  • Boost (Boost filesystem, program_options, regex, unit_test_framework and system are required)
  • expat

다음 같이 cmake 와 필요한 라이브러리를 apt로 설치한다.

1
2
sudo apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev \
libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev pkg-config

빌드

소스 다운로드:

1
2
git clone https://github.com/vitalif/grive2
cd grive2

CMake 로는 다음 같이 빌드 환경을 구성한다

1
2
3
mkdir build
cd build
cmake ..

그리고 Make 로 다음 같이 빌드한다:

1
make -j4

그리고 설치한다:

1
sudo make install

Updates

소스는 git pull 로 최신 소스를 얻고 다시 빌드한다:

1
2
3
4
5
6
cd /path/to/yourGriveSourceCodeDir/grive2
git pull
cd build
cmake ..
make -j4
sudo make install

Usage

인증

1
2
3
4
5
6
7
8
9
10
$ grive -a
-----------------------
Please go to this URL and get an authentication code:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%....client_id=22314510474.apps.googleusercontent.com
-----------------------
Please input the authentication code here:
5/dTdVFy9xBd2cKLYvkcvJlYhwfht4IPuyJdri2Vv3sKA
Reading local directories
Reading remote server file list

참조


## OneDrive, for Linux

OneDrive, for Linux를 설치해서 사용한다.

설치

https://github.com/skilion/onedrive 와 같이 다운로드해서 설치하거나 apt로 unstable apt로 설치할 수 있다.

source 설치

git-hub 가이드에 따라,

1
2
3
4
5
sudo apt-get install libcurl-dev
sudo apt-get install libsqlite3-dev
sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
wget -qO - http://dlang.org/d-keyring.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install dmd-bin

그런데 Armbian 에서 llibcurl-dev 패키지를 요구해서,

1
2
3
4
5
6
7
$ sudo apt-get install libcurl-dev
Reading state information... Done
Package libcurl-dev is a virtual package provided by:
libcurl4-openssl-dev 7.38.0-4+deb8u5
libcurl4-nss-dev 7.38.0-4+deb8u5
libcurl4-gnutls-dev 7.38.0-4+deb8u5
You should explicitly select one to install.

그래서 libcurl-dev을 설치했다

1
2
$ sudo apt-get install libcurl4-openssl-dev
$ sudo apt-get install libsqlite3-dev

설정

1
2
3
4
$ cat ~/.config/onedrive/config
sync_dir = "~/OneDrive"
skip_file = ".*|~*|thumbs.db|Games/*.iso"
skip_dir = ".*|Music|Movies/FullHD"

사용은

1
2
3
4
5
6
7
$ onedrive -h
Usage: onedrive [OPTION]...
no option Sync and exit.
-m --monitor Keep monitoring for local and remote changes.
--resync Forget the last saved state, perform a full sync.
-v --verbose Print more details, useful for debugging.
-h --help This help information.

참조

Cheat Linux System

Linux 에서 짬짬히 자주 쓰이는 명령을 설정을 정리.

  1. Disk
    • GRUB, fsck, dd
  2. System 설정
  3. rsync

비슷한 문서:

Disk

GRUB 복구

우분투 부트로더인 GRUB가 잘못되어 복구하려면 해당 배포본의 Live CD, Live USb 등으로 부팅해서 ‘Try Ubuntu’ 에서 터미널을 통해 복구 절차를 시작한다.

https://askubuntu.com/questions/88384/how-can-i-repair-grub-how-to-get-ubuntu-back-after-installing-windows

https://help.ubuntu.com/community/Grub2

https://wiki.ubuntu.com/Grub2#Recover

fsck

fsck(for file system consistency check) 명령은 파일 시스템을 조사하여 손상된 파일을 출력해 주며 사용자에게 그것을 복구할 것인지를 질의

fsck 수행은 시스템마다 약간의 차이가 있지만 대부분 다음과 같은 5개 항목에 대하여 검사

  • Blocks and sizes, Pathname, Connectivity, Reference count, Free List

1
$ sudo fsck –t ext2 /dev/hdb

Attempt to repair damaged blocks

1
$ sudo fsck –a

Repair damaged blocks interactively

1
$ sudo fsck -r <drive>

force

Forcing the check

You can also force fsck at boot time by passing fsck.mode=force, as a kernel parameter. This will check every filesystem you have on the machine.

/forcefsck

Create a file called forcefsck:

1
# touch /forcefsck

Now, reboot the system:

1
# reboot

Frce fsck on next boot using shutdown command (may not work on many modern distros)

The -F option force fsck on reboot, login as root and type the following command to reboot and run fsck:

1
# shutdown -rF now

링크

Changing the check frequency

By default, fsck checks a filesystem every 30 boots (counted individually for each partition). To change the frequency of checking, run:

1
$ sudo tune2fs -c 20 /dev/sda1

exFAT

리눅스테어 외부 USB 디스크를 exFAT로 포맷하고 사용한다면, exfat-fuseexfat-utils를 설치해 준다.

1
$ sudo apt install exfat-fuse exfat-utils

그리고 대부분 최신 리눅스 데스크탑은 USB 디스크를 더블클릭하면 자동마운트 해준다.

터미널에서는

1
2
3
$ sudo mkdir /media/my_usb
$ sudo mount -t exfat /dev/sdb1 /media/my_usb
$ sudo umount /dev/sdb1

참조

  1. https://wiki.archlinux.org/index.php/fsck

dd

블록 크기

디스크에 데이터를 쓸려면 디스크의 기본 블록 크기인 512B 보다 큰게 좋다. 또한 쓰기 속도를 증가시키기 위해서 디스크의 물리적 지형에 맞는 크기를 사용하는 것이 좋다. fdisk 같은 유틸리티로 정보를 확인할 수 있고 혹은 sysfs 정보를 확인할 수 있다.

1
2
3
4
5
6
/sys/block/sdX/size
/sys/block/sdX/queue/physical_block_size
/sys/block/sdX/queue/logical_block_size
/sys/block/sdX/sdXY/alignment_offset
/sys/block/sdX/sdXY/start
/sys/block/sdX/sdXY/size

디스크 지우기

dd에 데이터를 쓸려면 디스크의 기본 블록 크기인 512B 보다 커야 한다. 또한 쓰기 속도를 증가시키기 위해서 디스크의 물리적 지형에 맞는 크기를 사용하는 것이 좋다.

1
$ sudo dd bs=8k if=/dev/urandom of=/dev/rdisk2

fdisk 정보로 확인

1
2
3
4
5
6
7
8
9
10
11
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 59.6 GiB, 64021856256 bytes, 125042688 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 441CD64A-70D1-4A40-ACA8-05CAB62C5C89

Device Start End Sectors Size Type
/dev/sdb1 2048 8390655 8388608 4G Linux swap
/dev/sdb2 8390656 125042654 116651999 55.6G Linux LVM

fdisk 결과의 Sector size는 전체 용량과 섹터 크기를 계산하면 논릭적인 섹터의 크기를 확인할 수 있다.

1
2
echo $((64021856256/125042688))
512

Sector size (logical/physical): 512 bytes / 512 bytes 에서 물리 크기를 확인할 수 있다.

성능

dd 를 사용해서 1024 바이트를 1000000 블록에 걸쳐 쓰기를 수행한다 - 1GB

1
$ time sudo dd bs=1024 count=1000000 if=/dev/zero of=1GB_file

dd 를 사용해서 1GB 크기 파일을 1024 바이트씩 읽기를 한다.

1
$ time sudo dd bs=1024 if=1GB_file of=/dev/null

Verbose output

Sending an INFO signal to a running dd process makes it print I/O statistics to standard error and then resume copying. In the example below, dd is run in the background to copy 10 million blocks. The kill command makes it output intermediate I/O statistics, and when dd completes normally or is killed by the SIGINT signal, it outputs the final statistics.

1
2
3
4
5
6
7
8
$ dd if=/dev/zero of=/dev/null count=10MB & pid=$!
$ kill -s INFO $pid; wait $pid
3385223+0 records in
3385223+0 records out
1733234176 bytes (1.7 GB) copied, 6.42173 seconds, 270 MB/s
10000000+0 records in
10000000+0 records out
5120000000 bytes (5.1 GB) copied, 18.913 seconds, 271 MB/s

On systems lacking the INFO signal dd responds to the USR1 signal instead, unless the POSIXLY_CORRECT environment variable is set.

You can also try the status=progress option:

1
2
3
4
5
6
[~]$ dd if=/dev/zero of=/dev/null count=10MB status=progress
4708234752 bytes (4.7 GB, 4.4 GiB) copied, 4 s, 1.2 GB/s
10000000+0 records in
10000000+0 records out
5120000000 bytes (5.1 GB, 4.8 GiB) copied, 4.3516 s, 1.2 GB/s
[~]$
참조

System 설정

Time zone

1
$ sudo dpkg-reconfigure tzdata

Keyboard

Capslock과 Control key 교체하기

키맵 이용해서 다음 명령:

1
$setxkbmap -layout us -option ctrl:nocaps
1
2
3
sudo vi /etc/default/keyboard

XKBOPTIONS="ctrl:nocaps"
1
sudo dpkg-reconfigure keyboard-configuration

Terminal Reset

실수로 바이너리 파일을 cat 하거나 하여 글자들이 깨질때.. 터미널 리셋하는 방법

1
2
3
4
5
$ reset
$ tput sgr0
$ setterm -reset
$ setterm -initialize
$ Ctrl + V, Ctrl + O

System Info

1
2
3
cat /etc/os-release     # Raspbian
uname -a
cat /etc/issue

Hardware Info

1
2
3
4
5
6
lscpu
lshw
lspci
lsusb
lsblk // block devices
lspcmcia
1
cat /proc/cpuinfo

BIOS안의 시스템 정보

1
# dmidecode

memory

1
$ free -m

Architecture

1
$cat /etc/issue

Ubuntu 에서

1
$subo lsb_release -a
1
2
$ dpkg --print-architecture      //
armhf
1
2
3
4
5
6
$ uname -a
i686, i386은 32bit, x86_64는 64bit. armv7은 32bit, armv8은 64bit
$ uname -m // machine inf

$ uname -i // hw platform
$ uname -p // processor
1
$ arch // uname -m 과 동일

32bit 64bit 체크

1
$ getconf LONG_BIT // 시스템 구성 질의
1
2
3
4
5
$ file /bin/ls
ELF 32-bit LSB executable, ARM, EABI5 version 1 ..
ARM
arm 7 is 32 bit.
ARMv8-A, October 2011, 64-bit address space and 64-bit arithmetic 지원
1
2
3
4
5
$ uname -m // machine inf
i686 // 32bit
x86_64 // 64bit
armv7l // 32bit
armv8 // 64bit

rsync

http://www.joinc.co.kr/w/Site/Tip/Rsync

rsync -avzh source destination
-a : 심볼릭 링크, 속성, 퍼미션, 소유권 등 보존
-v : 자세한 정보출력
-z : 전송시 압축
-r : 하위디렉토리포함
-e ssh : ssh를 이용한 rsync 동기화
–stats : 결과출력

기본 옵션

1
rsync -av source/ destination/

include와 exclude

이 옵션을 이용해서 대상 파일을 추가하거나 제외 할 수 있다.

1
$ rsync -avz  --exclude 'data' id@192.168.56.101:/home/backups ./

별표(*)도 사용할 수 있다.

1
$ rsync -avz  --exclude '*.cache' id@192.168.56.101:/home/backups ./

증분 백업

수정/변경된 내용만 동기화한다.

rsync -avzh moniwiki/ /tmp/backups/
-h, –human-readable : output numbers in a human-readable format
-u : –update update only (don’t overwrite newer files)
–delete : 서버동기화후 원본에서 파일이 삭제되면 백업에서도 파일을 삭제
–remove-source-files :

1
2
$ rsync -av /home/ /backup/home/ # 원본 증분 백업
$ rsync -av --delete /home/ /backup/home/ #원본 증분 백업, 원본 파일 삭제시 사본에서도 삭제

동기화 옵션

delete 옵션

목적지에 파일이나 디렉토리가 존재할 경우 삭제하고 싶을 때 --delete 옵션을 사용한다.

1
rsync -avz --delete id@192.168.56.101:/home/backups ./

원본 삭제 옵션

--remove-source-files를 이용하면, 전송이 끝난 후 원본파일을 삭제한다.

1
$rsync --remove-source-files -zvh backup.tar /tmp/backups/

ssh 통한 백업

rsync 에는 ssh 를 이용하여 원격서버에 접속하여 동기화를 하는 기능이 있습니다.

1
rsync -azrtv --delete --stats -e "ssh -i /root/.ssh/개인키" 원본서버계정@원본서버주소:원본경로/ /백업경로/

find와 결합

1
find . -type f -mtime -3  | rsync -avz --files-from=- /soucepc /data/backup

faillog

/var/log/faillog 는 계정의 로그인 실폐 횟수 정보를 바이너리 파일로 저장한다. 다음 C struct 구조의 정보가 바이너리로 저장되고 있다:

1
2
3
4
5
6
7
struct    faillog {
short fail_cnt;
short fail_max;
char fail_line[12];
time_t fail_time;
long fail_locktime;
};

직접 읽을 수 없기 때문에 faillog 명령을 사용한다.

1
2
3
4
5
6
$ faillog -u pi        # pi 계정
$ faillog -a
Login Failures Maximum Latest On

root 0 0 01/01/70 00:00:00 +0000
daemon 0 0 01/01/70 00:00:00 +0000

최근 3일의 로그인 실패를 찾으려면 :

1
$ faillog -t 3 -u pi

vnc server

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-14-04

http://www.whatwant.com/840

1
$ sudo apt-get install gnome-panel tightvncserver

첫 실행을 해서 기본 Config 등의 구성을 하도록 하면 되는데, sudo 없이 계정 권한으로 실행하여도 된다. 계정 권한으로 실행을 하면 해당 계정으로 환경 설정을 한다.

1
$ vncserver

실행할 때에 해상도를 미리 정해줘야 한다.

1
$ vncserver -geometry 1024x768

기본 창 관리자 변경

기본 생성된 xstartup 파일에는 내가 원하는 대로 환경 설정이 되어 있지 않다. 가장 먼저 실행된 vnc4server를 종료부터 하고 xstartup 파일을 수정하자.

1
2
3
4
$ vncserver -kill :1
$ cp ~/.vnc/xstartup ~/.vnc/xstartup.old

$ nano ~/.vnc/xstartup