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.
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.
If I've interpreted the question rightly, directory-local variables are a potential workaround. This would be overridden if there were dir-local configs nearer to the path in question, however, so YMMV.
(dir-locals-set-class-variables
'read-only
'((nil . ((buffer-read-only . t)))))
(dir-locals-set-directory-class "/ssh:user@server:/" 'read-only)
I'm still able to for example touch a file in the specified directory.
That's got nothing to do with Emacs. You're asking for Emacs to employ OS-level access controls, which it can't do, because it's not the OS. In your case it's not even running on the same machine.
You need to create a new user with more limited access, and connect as that user instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.