Search code examples
sshemacsreadonlytramp

Emacs SSH - Enforce read-only


Is there any possibility to connect to an SSH server using /ssh:user@server with read-only access, even if the account has write access? I need this to prevent accidental write.

Here is the function I use to connect:

(defun connect-b2b ()
  (interactive)
  (find-file-other-window "/ssh:user@server:/")
  buffer-read-only)
 (global-set-key (kbd "C-c C-d") 'connect-b2b)

Note that buffer-read-only does not help, neither does vc-toggle-read-only.

Update: Just to be clear what I want to achieve, I have an account with read+write access, however since this is a business critical server I wanted to prevent accidental changes. Unfortunately I cant change permissions on the user account itself, therefore I wanted to enforce this locally.


Solution

  • Third suggestion: Use sshfs to provide the remote filesystem locally, and mount it read-only, and then point Emacs at that.

    That way you're not subject to all of the pitfalls of being able to run commands directly on the remote server as a user who has write-permissions.