2010년 5월 4일 화요일

root 권한으로 파일실행

sudo






sudo가 설치가 안되어 있으면 visudo 등을 사용....
















sudo 설치된 상태에서 /etc/sudoers에서 설정하면 특정 그룹에 있는 user가 sudo 명령어 사용할때 passwd 안묻도록 할 수 있음


























if you really want to have a script run as a user and be able to execute commands as root, there are 2 options that I know of.
















  1. Use sudo with stored password:

    #!/bin/sh
    whoami
    sudo -S -p "" whoami <<EOF
    mysuperpassword
    EOF





    Which will output (when run as 'user'):

    user
    root










  2. Use sudo with no password.
    Add a list of the commands that you wish to run into the /etc/sudoers file by running visudo as root. For example, to allow user to run the commands apache2ctl and whoami, add the following:

    User_Alias SPECIAL = user
    Cmnd_Alias SPECIAL_COMMANDS = /usr/sbin/apache2ctl, /usr/bin/whoami
    SPECIAL ALL = NOPASSWD: SPECIAL_COMMANDS





    Or if you really trust user, if it's you for example, you can allow the user to execute any command without a password:

    user ALL=(ALL) NOPASSWD: ALL





    Then when the following script is run by user:

    #!/bin/sh
    whoami
    sudo whoami





    It will output:

    user
    root