Home > cloud > Creating a pseudoterminal to make sudo happy

Creating a pseudoterminal to make sudo happy

October 24Hits:1
Advertisement

I need to automate the provisioning of a cloud instance (running Fedora 17) for which the following initial facts are true:

  • I have ssh-key based access to a remote user (cloud)
  • That user has password-free root access via sudo.

Manual configuration is as simple as logging in and running sudo su - and having at it, but I would like to fully automate this process. The trick is that the system defaults to having the requiretty option enabled for sudo, which means that an attempt to do something like this:

ssh remotehost sudo yum -y install puppet 

Will fail:

sudo: sorry, you must have a tty to run sudo 

I am working around this right now by first pushing over a small Python script that will run a command on a pseudoterminal:

import os import sys import errno import subprocess  pid, master_fd = os.forkpty()  if pid == 0:     # child process: now that we're attached to a     # pty, run the given command.     os.execvp(sys.argv[1], sys.argv[1:]) else:     while True:         try:             data = os.read(master_fd, 1024)         except OSError, detail:             if detail.errno == errno.EIO:                 break          if not data:             break          sys.stdout.write(data)      os.wait() 

Assuming that this is named pty, I can then run:

ssh remotehost ./pty sudo yum -y install puppet 

This works fine, but I'm wondering if there are solutions already available that I haven't considered.

  • I would normally think about expect, but it's not installed by default on this system.
  • screen can do this in a pinch, but the best I came up with was:
    screen -dmS sudo somecommand 
    

    ...which does work but eats the output.

Are there any other tools available that will allocate a pseudoterminal for me that are going to be generally available?

Answers

You want the -t option to ssh:

 -t      Force pseudo-tty allocation.  This can be used to execute
         arbitrary screen-based programs on a remote machine, which can be
         very useful, e.g. when implementing menu services.  Multiple -t
         options force tty allocation, even if ssh has no local tty.

You may need to use -tt if the script is going to be run non-interactively.

Why don't you just comment out the requiretty-line in /etc/sudoers ?

Related Articles

  • Creating a pseudoterminal to make sudo happyOctober 24

    I need to automate the provisioning of a cloud instance (running Fedora 17) for which the following initial facts are true: I have ssh-key based access to a remote user (cloud) That user has password-free root access via sudo. Manual configuration is

  • how would I create a tar without using sudo?October 3

    If I tar my /home/username and create the .tar file in /home/username, then I get an error of the sort . file changed as we read it probably because the directory file itself is changing due to the creation of the .tar file. Of course I could have th

  • Does oem-config create a user not in sudo group?February 7

    My friend just bought a netbook with Xubuntu preinstalled and the user was created right in store without giving her a root password. Neither was it an admin user. Was it oem-config's fault or store stаff's? Tip: To solve this boot into recovery mode

  • How can I create DB2 objects with Linux SUDOer authority?February 27

    All, I am relatively new to Red hat linux and I have SUDOer authority but unable to create DB2 database or other objects. How can I accomplish this task? Please give examples. Also, is there any known freeware or trial tool for converting mainframe d

  • Creating a normal user without sudo access but with ability to switch to another admin userMay 7

    User A - can't be part of sudo or admin group, ssh keys based identity setup for ssh login, can't be a guest account User B - no home folder, must have a password, can't have independent ssh login, should be part of sudo / admin group User A don't ne

  • Creating a group in trying not to use Sudo nor 777August 31

    How can you create a group such that I can use programs of another user in the PC in my user account without 777 permissions nor with sudo? I created a new user by sudo adduser masi. I need either to change each program's permissions to be 777 at /us

  • create a linux user with create files and write permissions without sudo accessMay 6

    I want to create a user in such a way that it can create a file and update the contents of the file. useradd username Now for sudo, we can create username and linking to sudo like below: useradd username sudo But I dont want to give sudo access. With

  • Why does sudo ask for a password in window after I've just authenticated in a different one?

    Why does sudo ask for a password in window after I've just authenticated in a different one?February 10

    If I am using the command line in xterm, gnome-terminal, etc., I can keep sudo from re-prompting for a password, within some limits, or I can disable it. As a compromise between usability and security, I usually just want this re-querying wait-time l

  • sudo logs date with user's locale, apparently. How do I make it use "C" locale?March 5

    I have sudo set to log to /var/log/sudo.log. I've noticed that when the locale was set to "de_DE.UTF-8", it logged a localized date ("Mär" for "März") instead of "C" locale ("Mar" for "March"). H

  • How do I create a Launcher in Ubuntu 9.10 that runs a shell script?March 24

    Here's my situation: New to Ubuntu (just installed 9.10 Karmic Koala 64 bit) Purpose: to easily run PyCharm without too much typing (ie. cd... ./pycharm.sh) Want to create desktop Launcher instead of terminal & typing (without resorting to the "R

  • How i can creat user with privilege in ubuntu 10.04 severAugust 30

    How can I create users with privilege in ubuntu 10.04 server by using CLI --------------Solutions------------- Create a (normal) user: sudo adduser Give user sudo rights. Default all admin users can sudo, so you can just move your new user into that

  • How do I create an administrator user on Ubuntu?October 7

    I want to create a user having sudo powers in Ubuntu. How can I do that? --------------Solutions------------- First, create the user with: sudo adduser <username> You can read more about this command in the man pages of your system with man adduser.

  • How do I create a new file and edit it as root?February 27

    I've tried: gksudo gedit /etc/xinetd.d/tftp (this is the path I need). I got an error message: couldn't find the file /etc/xinetd.d/tftp please check that you typed the location correctly and try again What do I need to do? --------------Solutions---

  • Why no first user setup as sudo on Linode (Ubuntu 10.10)May 12

    The standard setup for Ubuntu is to create two users, root and a first user. The first user always gets full sudo access and root login is disabled (for security). Linode doesn't do this, it just creates root, with ssh login enabled. Why is this so?

  • How do I create my own Ubuntu version?

    How do I create my own Ubuntu version? June 13

    I would like to customize Ubuntu live CD by installing some additional packages. I have followed this but it doesn't seems to work. Can anyone provide clear instructions? Note: I do not prefer Remastersys, manual way will be appreciated. Customizatio

  • Can I create a LiveUSB from Ubuntu 12.04 without having the original ISO file?

    Can I create a LiveUSB from Ubuntu 12.04 without having the original ISO file? June 13

    I would like to customize Ubuntu live CD by installing some additional packages. I have followed this but it doesn't seems to work. Can anyone provide clear instructions? Note: I do not prefer Remastersys, manual way will be appreciated. Customizatio

  • Creating a spin from my installation

    Creating a spin from my installation June 13

    I would like to customize Ubuntu live CD by installing some additional packages. I have followed this but it doesn't seems to work. Can anyone provide clear instructions? Note: I do not prefer Remastersys, manual way will be appreciated. Customizatio

  • How to create your own Ubuntu Distribution based on Ubuntu 12.10?

    How to create your own Ubuntu Distribution based on Ubuntu 12.10? June 13

    I would like to customize Ubuntu live CD by installing some additional packages. I have followed this but it doesn't seems to work. Can anyone provide clear instructions? Note: I do not prefer Remastersys, manual way will be appreciated. Customizatio

  • How to create modified Kubuntu Live/Install DVD?

    How to create modified Kubuntu Live/Install DVD? June 13

    I would like to customize Ubuntu live CD by installing some additional packages. I have followed this but it doesn't seems to work. Can anyone provide clear instructions? Note: I do not prefer Remastersys, manual way will be appreciated. Customizatio

  • How to create a custom ubuntu cd?

    How to create a custom ubuntu cd? June 13

    I would like to customize Ubuntu live CD by installing some additional packages. I have followed this but it doesn't seems to work. Can anyone provide clear instructions? Note: I do not prefer Remastersys, manual way will be appreciated. Customizatio

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.701 s.