summaryrefslogtreecommitdiff
path: root/src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2021-05-07 17:10:36 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2021-05-07 17:10:36 +0100
commitc709d0c51f03b3010d8f2f19ee73f96c6a06ffe0 (patch)
tree634d47bed88caa3e8bccfa3d479a250da67685e1 /src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi
parent3fa6047100fed4bb92889c21d3043f41eb314507 (diff)
Convert existing posts to gemtext
Diffstat (limited to 'src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi')
-rw-r--r--src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi b/src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi
new file mode 100644
index 0000000..f34f3f0
--- /dev/null
+++ b/src/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/index.gmi
@@ -0,0 +1,47 @@
+# Sudo: sorry, you must have a tty to run sudo
+
+> Mon 13th July 2020 By David T. Sadler.
+
+I have found Deployer to be a great tool for deploying PHP applications. However when first setting out to use it I soon came across the error message 'sudo: sorry, you must have a tty to run sudo'. After some investigation I found that the error was triggered when Deployer was running commands via sudo. For those that don't know Deployer works by executing commands on your servers via ssh and depending on your server's configuration there could be issues when sudo is one of those commands.
+
+## What is meant by 'sudo: sorry, you must have a tty to run sudo'?
+
+When sudo is executed the file /etc/sudoers is read to determine which users or groups can use sudo and what commands they can run. It actually does a bit more than that and you should read the manual for more information.
+
+If you examine the sudoers file you will find that it contains the setting Defaults requiretty. This means that sudo can only be ran from a real tty. In other words if a user wants to run sudo they must have logged into a terminal before hand. This is normally a security feature so that sudo can't be ran from things such as cron jobs. However, it also means that you will have issues when running sudo from another machine via ssh as you also won't be logged into an actual terminal.
+
+## How to resolve the issue?
+
+If you're happy to change the setting for all users simply use visudo to edit /etc/sudoers and change Defaults requiretty to Defaults !requiretty. Alternatively you can remove the tty requirement for a single user. In fact that is what I do when using Deployer. Since it connects to the server using a user called deployer I add the below configuration with visudo.
+
+```shell
+Defaults:deployer !requiretty
+deployer ALL=(ALL) NOPASSWD:/usr/bin/chown, /usr/bin/tee, /usr/sbin/apachectl
+```
+
+This configuration allows the deployer user to execute sudo when not logged into a real terminal and additionally not prompt for a password when executing chown, tee, and apachectl.
+
+## Using Pseudo-tty
+
+An alternative is to use the pseudo-tty option when connecting via ssh.
+
+```shell
+$ ssh -t user@example.com sudo apachectl restart
+```
+
+### Links
+
+=> https://deployer.org/ Deployer - A Deployment Tool for PHP.
+=> https://www.sudo.ws/man/sudoers.man.html Sudo Manual.
+
+=> /posts/linux/ Linux - Read More Posts.
+
+I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.
+
+=> mailto:david@davidtsadler.com Email david@davidtsadler.com
+
+=> https://creativecommons.org/licenses/by-sa/4.0/ The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
+
+Copyright © 2021 David T. Sadler.
+
+=> / Return to Homepage.