all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs client doesn't run by root
@ 2021-02-28 19:10 Tim Johnson
  2021-02-28 20:09 ` Tassilo Horn
  2021-03-01  6:00 ` Teemu Likonen
  0 siblings, 2 replies; 5+ messages in thread
From: Tim Johnson @ 2021-02-28 19:10 UTC (permalink / raw)
  To: MLEmacs

I have been using the emacs daemon as my system editor.
Starting with the following script
;; code
emacs -q -nw --no-splash --daemon -l ~/.emacs.d/init_term.el
;; end code

Works fine as user tim, but if I try it as root, I get the following error
message:
;; quote
/usr/local/bin/emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
/usr/local/bin/emacsclient: No socket or alternate editor.  Please use:

     --socket-name
     --server-file      (or environment variable EMACS_SERVER_FILE)
     --alternate-editor (or environment variable ALTERNATE_EDITOR)
;; end quote

What else needs to be done?

Using emacs GNU Emacs 26.3 on ubuntu 16.04

thanks

-- 
Tim
tj49.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs client doesn't run by root
  2021-02-28 19:10 Emacs client doesn't run by root Tim Johnson
@ 2021-02-28 20:09 ` Tassilo Horn
  2021-02-28 21:54   ` Tim Johnson
  2021-03-01  6:00 ` Teemu Likonen
  1 sibling, 1 reply; 5+ messages in thread
From: Tassilo Horn @ 2021-02-28 20:09 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Johnson <tim@akwebsoft.com> writes:

> I have been using the emacs daemon as my system editor.
> Starting with the following script
> ;; code
> emacs -q -nw --no-splash --daemon -l ~/.emacs.d/init_term.el
> ;; end code
>
> Works fine as user tim, but if I try it as root, I get the following error
> message:
> ;; quote
> /usr/local/bin/emacsclient: can't find socket; have you started the server?

The reason is that this will try to connect to the emacs demon run for
the user root which you would need to start as well.

I just find files as normal user and use the below snippet to be queried
if I want to open a file I have no write permission for using TRAMP's
sudo method:

--8<---------------cut here---------------start------------->8---
  (defun th/find-file-sudo (file)
    "Opens FILE with root privileges."
    (interactive "F")
    (set-buffer (find-file (concat "/sudo::" file))))

  (define-advice find-file (:around (ff file &rest more) th/find-file-maybe-sudo)
    (if (and (file-exists-p file)
             (not (file-directory-p file))
             (not (file-writable-p file))
             (not (file-remote-p file))
             (y-or-n-p (concat "File "
                               file
                               " is read-only.  Sudo? ")))
        (th/find-file-sudo file)
      (funcall ff file more)))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs client doesn't run by root
  2021-02-28 20:09 ` Tassilo Horn
@ 2021-02-28 21:54   ` Tim Johnson
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Johnson @ 2021-02-28 21:54 UTC (permalink / raw)
  To: help-gnu-emacs


On 2/28/21 11:09 AM, Tassilo Horn wrote:
> Tim Johnson <tim@akwebsoft.com> writes:
>
>> I have been using the emacs daemon as my system editor.
>> Starting with the following script
>> ;; code
>> emacs -q -nw --no-splash --daemon -l ~/.emacs.d/init_term.el
>> ;; end code
>>
>> Works fine as user tim, but if I try it as root, I get the following error
>> message:
>> ;; quote
>> /usr/local/bin/emacsclient: can't find socket; have you started the server?
> The reason is that this will try to connect to the emacs demon run for
> the user root which you would need to start as well.
>
> I just find files as normal user and use the below snippet to be queried
> if I want to open a file I have no write permission for using TRAMP's
> sudo method:
>
> --8<---------------cut here---------------start------------->8---
>    (defun th/find-file-sudo (file)
>      "Opens FILE with root privileges."
>      (interactive "F")
>      (set-buffer (find-file (concat "/sudo::" file))))
>
>    (define-advice find-file (:around (ff file &rest more) th/find-file-maybe-sudo)
>      (if (and (file-exists-p file)
>               (not (file-directory-p file))
>               (not (file-writable-p file))
>               (not (file-remote-p file))
>               (y-or-n-p (concat "File "
>                                 file
>                                 " is read-only.  Sudo? ")))
>          (th/find-file-sudo file)
>        (funcall ff file more)))
> --8<---------------cut here---------------end--------------->8---
Thanks. It is solved. Cheers

-- 
Tim
tj49.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs client doesn't run by root
  2021-02-28 19:10 Emacs client doesn't run by root Tim Johnson
  2021-02-28 20:09 ` Tassilo Horn
@ 2021-03-01  6:00 ` Teemu Likonen
  2021-03-01 18:39   ` Tim Johnson
  1 sibling, 1 reply; 5+ messages in thread
From: Teemu Likonen @ 2021-03-01  6:00 UTC (permalink / raw)
  To: Tim Johnson, MLEmacs

[-- Attachment #1: Type: text/plain, Size: 681 bytes --]

* 2021-02-28 10:10:05-0900, Tim Johnson wrote:

> I have been using the emacs daemon as my system editor.

> Works fine as user tim, but if I try it as root, I get the following
> error message:

Another option is to use "sudoedit" (or "sudo -e") instead of "sudo
emacsclient". "sudoedit" uses root access to copy the target file to a
temporary location for the current user. Then it starts editing the file
with user's default text editor and finally moves the temporary file to
the original location. This way the editor doesn't run as the root user.

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs client doesn't run by root
  2021-03-01  6:00 ` Teemu Likonen
@ 2021-03-01 18:39   ` Tim Johnson
  0 siblings, 0 replies; 5+ messages in thread
From: Tim Johnson @ 2021-03-01 18:39 UTC (permalink / raw)
  To: help-gnu-emacs



On 2/28/21 9:00 PM, Teemu Likonen wrote:
> * 2021-02-28 10:10:05-0900, Tim Johnson wrote:
>
>> I have been using the emacs daemon as my system editor.
>> Works fine as user tim, but if I try it as root, I get the following
>> error message:
> Another option is to use "sudoedit" (or "sudo -e") instead of "sudo
> emacsclient". "sudoedit" uses root access to copy the target file to a
> temporary location for the current user. Then it starts editing the file
> with user's default text editor and finally moves the temporary file to
> the original location. This way the editor doesn't run as the root user.
Cool. Thanks!

-- 
Tim
tj49.com




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-01 18:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-28 19:10 Emacs client doesn't run by root Tim Johnson
2021-02-28 20:09 ` Tassilo Horn
2021-02-28 21:54   ` Tim Johnson
2021-03-01  6:00 ` Teemu Likonen
2021-03-01 18:39   ` Tim Johnson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.