[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Would like to have tramp pass sudo arg

From: Tom Wurgler
Subject: Would like to have tramp pass sudo arg
Date: Fri, 31 Aug 2018 14:31:33 +0000

I have the following code, which works well to a point:

(defun sudo-shell-as-user (host user &optional arg)
  "Use sudo to open a shell on HOST as USER
The password it asks for is the root password on the specified machine."
  (interactive "sMachine? \nsUser? ")
  (let* ((tramp-default-proxies-alist
      `((,(regexp-quote host)
         ,(regexp-quote user)
     (dir "")
     (arg (if arg arg 1))
     (newone (if (not (string-match "/sudo:" default-directory)) t nil))
     (default-directory (if newone (concat "/sudo:" user "@" host ":") default-directory)))
    (setq bname (concat "*ssh-sudo:" user "@" host "*<" (number-to-string arg) ">"))
    (shell bname)
    (if (string-match dir ".") (setq dir "~"))
    (if newone
      (sit-for 2)
      (insert (concat "cd " dir))

This lets me log in as the user using sudo to the specified computer.
But I don't have that that user's environment.  I *think* what I need is the option "-i" or "--login" to the command sudo.  But I can't figure how to get it in there.

Is this possible?  Is this what I even need?

Any input appreciated.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]