Рекомендации по использованию sudo в сценарии bash

Сначала установите приложение stardict.

sudo apt-get install stardict

Затем откройте компакт-диск. Найдите файл oald.zip внутри папки linux и вставьте его на рабочий стол. Затем извлеките файл. Будут oald.dict и oald.idx файлы.

Скопируйте этот файл и вставьте его в папку

/usr/share/stardict/dic

, вы можете использовать словарь с stardict

** Также вы можете запустить файл setup.sh

Перейти в папку linux. Тогда

sudo bash setup.sh
5
задан 25 July 2017 в 15:52

6 ответов

Что касается метода 2, проще использовать функцию. Например:

#!/bin/bash

func(){
    echo "Username: $USER"
    echo "    EUID: $EUID"
}

export -f func

func
su "$SUDO_USER" -c 'func'

$SUDO_USER - имя пользователя sudoer. Вы также можете использовать $(logname) на своем месте.

Выполняется на моей машине:

$ sudo bash test.sh
[sudo] password for wja: 
Username: root
    EUID: 0
Username: wja
    EUID: 1000
4
ответ дан 22 May 2018 в 20:12

Что касается метода 2, проще использовать функцию. Например:

#!/bin/bash func(){ echo "Username: $USER" echo " EUID: $EUID" } export -f func func su "$SUDO_USER" -c 'func'

$SUDO_USER - имя пользователя sudoer. Вы также можете использовать $(logname) на своем месте.

Выполняется на моей машине:

$ sudo bash test.sh [sudo] password for wja: Username: root EUID: 0 Username: wja EUID: 1000
4
ответ дан 18 July 2018 в 09:42

Что касается метода 2, проще использовать функцию. Например:

#!/bin/bash func(){ echo "Username: $USER" echo " EUID: $EUID" } export -f func func su "$SUDO_USER" -c 'func'

$SUDO_USER - имя пользователя sudoer. Вы также можете использовать $(logname) на своем месте.

Выполняется на моей машине:

$ sudo bash test.sh [sudo] password for wja: Username: root EUID: 0 Username: wja EUID: 1000
4
ответ дан 24 July 2018 в 19:24

Считая man sudoers, вы видите:

 PASSWD and NOPASSWD

   By default, sudo requires that a user authenticate him or herself
   before running a command.  This behavior can be modified via the
   NOPASSWD tag.  Like a Runas_Spec, the NOPASSWD tag sets a default for
   the commands that follow it in the Cmnd_Spec_List.  Conversely, the
   PASSWD tag can be used to reverse things.  For example:

   ray     rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

   would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm
   as root on the machine rushmore without authenticating himself. 

Таким образом, вы можете разрешить regular на хосте machine1 выполнить command1 и command2 как root, без аутентификации пароля с:

reguser machine1 root = NOPASSWD: /usr/local/command1, /usr/local/command2  

, но прочитайте каждый из man -k sudo для деталей.

1
ответ дан 22 May 2018 в 20:12

Считая man sudoers, вы видите:

PASSWD and NOPASSWD By default, sudo requires that a user authenticate him or herself before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for the commands that follow it in the Cmnd_Spec_List. Conversely, the PASSWD tag can be used to reverse things. For example: ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm as root on the machine rushmore without authenticating himself.

Таким образом, вы можете разрешить regular на хосте machine1 выполнить command1 и command2 как root, без аутентификации пароля с:

reguser machine1 root = NOPASSWD: /usr/local/command1, /usr/local/command2

, но прочитайте каждый из man -k sudo для деталей.

1
ответ дан 18 July 2018 в 09:42

Считая man sudoers, вы видите:

PASSWD and NOPASSWD By default, sudo requires that a user authenticate him or herself before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for the commands that follow it in the Cmnd_Spec_List. Conversely, the PASSWD tag can be used to reverse things. For example: ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm as root on the machine rushmore without authenticating himself.

Таким образом, вы можете разрешить regular на хосте machine1 выполнить command1 и command2 как root, без аутентификации пароля с:

reguser machine1 root = NOPASSWD: /usr/local/command1, /usr/local/command2

, но прочитайте каждый из man -k sudo для деталей.

1
ответ дан 24 July 2018 в 19:24

Другие вопросы по тегам:

Похожие вопросы: