Wie kann ich eine Datei oder einen Ordner für einen anderen Benutzer kopieren? Die neue Datei oder der neue Ordner muss seinen Namen haben.
Ich habe Sudo-Zugriff für den CP-Befehl
USER1 ALL=(ALL) NOPASSWD: /bin/cp
Ich versuche folgenden Befehl:
USER1@ySERVERNAME:HOME_PATH$ sudo -i -u USER2 cp file1 file2
Ich habe einen Fehler erhalten:
Sorry, user USER1 is not allowed to execute '/bin/bash -c cp file1 file2' as USER2 on SERVERNAME.
Wie kann ich es lösen?
Antwort1
Lösung:
Sie sollten Folgendes -i
aus dem sudo
Befehl entfernen:
sudo -u USER2 cp file1 file2
Erläuterung:
Ihr Problem besteht darin, dass Ihr sudo
Zugriff auf erforderliche zusätzliche Berechtigungen beschränkt ist /bin/cp
und diese Sie nicht besitzen.sudo -i
sudo
Wie im Fehler angegeben:
Entschuldigung, Benutzer USER1 darf „/bin/bash -c cp file1 file2“ nicht als USER2 auf SERVERNAME ausführen.
Bei der Verwendung sudo -i -u USER2 cp
des von Ihnen ausgeführten Befehls /bin/bash -c cp
verfügen Sie nicht über sudo
die Berechtigung. Sie sind auf den Befehl beschränkt, für den Sie sudo
die Berechtigung haben: /bin/cp
.
Mehr Info:Mann sudo
-i, --login Run the shell specified by the target user's password database entry as a login shell. This means that login- specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell's -c option. If no command is specified, an interactive shell is executed. sudo attempts to change to that user's home directory before running the shell. The command is run with an environment similar to the one a user would receive at log in. The Command environment section in the sudoers(5) manual documents how the -i option affects the environment in which a command is run when the sudoers policy is in use.