[Linux] sudo 사용을 위한 sudoers 설정

sudo 그룹이 이미 있는 경우가 많으므로, 그냥 아래 명령을 root권한으로 주는 것이 더 낫다. 아닌 경우 그 아래 내용을 참고한다.

# usermod -aG sudo username

sudo 에 관한 설정을 바꿀 때는 /etc/sudoers 파일을 직접 고치는 것 보다는 /etc/sudoers.d/ 안에 설정 파일을 추가하는 것이 좋다.

새로운 사용자를 추가하려면 다음과 같이 파일을 추가한다.

sudo visudo -f /etc/sudoers.d/011_dasomoli-sudoer
dasomoli ALL=(ALL)   ALL

sudo를 할 때 아예 패스워드를 묻지 않게 할 수도 있는데, 라즈베리 파이3의 경우, 이를 이용해서 기본 계정의 경우 NOPASSWD: ALL 을 줘서 sudo 시 패스워드를 묻지 않도록 하고 있다.

vi /etc/sudoers.d/010_pi-nopasswd
pi ALL=(ALL) NOPASSWD: ALL

[RaspberryPi] Torrent 머신 만들기

Torrent 파일을 등록해놓으면, 집에 있는 서버에 해당 파일을 자동으로 다운로드 받아놓는다. transmission을 설치하면 된다.

# apt-get install transmission-cli transmission-common transmission-daemon
# service transmission-daemon stop
# vi /etc/transmission-daemon/settings.json

설정 파일의 다음 항목을 수정한다.

"download-dir": "/mnt/NAS/TorrentDownload",
"rpc-username": "dasomoli",
"rpc-password": "password",
"rpc-whitelist-enabled": false,
"umask": 2,

업로드 속도를 제한하고 싶다면 다음을 수정한다. 예를 들어, 10 KB/sec 로 제한한다면

"speed-limit-up": 10,
"speed-limit-up-enabled": true,

기본 포트를 바꾸고 싶다면 다음을 수정한다.

"rpc-port": 9000

# service transmission-daemon reload
# usermod -aG debian-transmission dasomoli

download-dir은 다운로드 받을 디렉토리, rpc-username은 웹 인터페이스로 들어갈 때 로그인 할 ID, rpc-password는 그 Password이다. rpc-whitelist-enabled를 false 로 설정하면, 말 그대로 whitelist를 사용하지 않으므로, 어디에서든 접속이 가능하다.

접속은 기본은 9091 포트로 접속하면 된다. 위에선 9000으로 바꿨다. 하지만, 포트 번호를 치긴 귀찮으므로 apache2의 proxy를 이용해서 접속하자.

# vi /etc/apache2/sites-available/torrent.dasomoli.org.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName torrent.dasomoli.org
        ServerAdmin dasomoli@gmail.com

        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/torrent.log
        CustomLog ${APACHE_LOG_DIR}/torrent.access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

이제 proxy 모듈을 enable하고, site를 enable한 후, apache2를 재시작하자.

# a2enmod proxy
# a2enmod proxy_http
# a2ensite torrent.dasomoli.org.conf
# service apache2 restart

# sudo service transmission-daemon start

이제 http://torrent.dasomoli.org 로 접속하면 된다.
당연히 미리 DNS설정은 되어 있어야 한다.

부팅 시에 Web UI 가 연결이 안되는 경우가 있는데, 이 때는 transmission-daemon을 reload 하면 된다. 수많은 해결(이라고 주장하는) 방법이 있지만, 가장 간단하면서 잘 동작하는 방법은 그냥 raspi-config에서 “Network at Boot:”의 “Wait for network”을 체크하는 것이다.

가장 간단하지만 잘 동작하는 허무한 해결책…

참고: https://askubuntu.com/questions/157455/how-to-change-the-default-permissions-of-files-created-by-transmission-daemon

[Eclipse] Source code Navigation 단축키

Eclipse는 내부적으로 Indexer가 돌아서 이를 이용해 찾고 싶은 File, Funtion decalaration/definition, symbol 등을 찾을 수 있다. 내가 자주 쓰는 단축키는 다음과 같다.

  • F3: Funtion declaratiin/definition. 함수 선언이나, 함수 정의로 이동하고 싶을 때 사용한다.
  • Alt + ‘<-‘: 이전 코드. 이전에 보던 부분으로 돌아갈 때 사용한다.
  • Ctrl + Shift + ‘R’: File name 찾아서 열기. 파일 이름을 알 때, 혹은 앞 몇글자만 기억날 때, 찾아서 연다.
  • Ctrl + Shift + ‘G’: Workspace에서 Reference 찾기. 함수 호출되는 부분을 찾고 싶을 때 사용한다.
  • Ctrl + ‘H’: Search. 주로 File Search를 이용한다. Scope을 셋팅해서 쓰는 것도 좋다.
  • Ctrl + Alt + ‘G’: Workspace에서 Text 찾기. Ctrl + ‘H’ 대신 사용하기도 한다.
  • Ctrl + ‘O’: Quick Outline. 주로 함수를 찾아 이동할 때 사용한다.

curl 사용법

curl 잘쓰면 엄청 편하다.
* HTTP 전송 과정에 대한 상세 정보. curl이 하는 모든 일을 debugdump.txt에 저장한다.
curl –trace-ascii debugdump.txt http://blog.dasomoli.org/
* 일반적인 http 요청(GET method)
curl http://blog.dasomoli.org/
* HTTP authentication
curl -u <id>:<password> http://blog.dasomoli.org/
* POST method 요청
curl -X POST -d”<data>” http://blog.dasomoli.org:80/post/
다음과 같은 form이 있다면,
<form method=”POST” action=”dasomoli.cgi”>
<input type=text name=”id”>
<input type=submit name=press value=” OK “>
</form>
다음과 같이 전송 가능((hidden type도 그냥 쓰면 됨)
curl –data “id=dasomoli&press=%20OK%20”  http://blog.dasomoli.org/dasomoli.cgi
–data-urlencode를 쓰면 %20같이 쓰지 않고, 아래처럼도 가능하다고 한다.
curl –data-urlencode “name=JeongSeok Yang” http://blog.dasomoli.org/dasomoli.cgi
* POST로 파일 보내기
curl -X POST -d@<filename> http://blog.dasomoli.org/post/
* PUT method
curl –upload-file uploadfile http://blog.dasomoli.org/receiveput.cgi
* JSON 전송
curl -X POST http://blog.dasomoli.org/json/ -d@dasomoli.json -H “Content-Type: application/json”
* 쿠키 쓰기
curl -b cookie.txt -c cookie.txt http://blog.dasomoli.org/

 

 

윈도우즈 전원 설정 command tool: powercfg

컴퓨터 전원 옵션을 자꾸만 건드리는 툴, 예를 들면, 보안 프로그램이라던지, 보안 프로그램이라던지, 보안 프로그램이라던지..가 껐다켜면 자꾸 내 전원 옵션을 잠깐 안쓰면 절전모드로 바꾸게 해둔다.
제어판에서 내가 원하는 전원 옵션, 즉, 항상 켜는 전원 옵션을 만들고. 커맨드 프롬프트에서 powercfg -l 을 입려하면 만든 옵션의 GUID가 나온다.
이걸 커맨드 툴로 셋팅하려면 powercfg -SETACTIVE 하면 적용된다.
이걸 시작 프로그램에 등록하자. ㅋㅋㅋ