This package facilitates automatic privilege escalation for file permissions using TRAMP.
You can install the package by either cloning it yourself, or by doing M-x package-install
RET su
RET.
After that, you can enable it by putting the following in your init file:
(su-mode +1)
# If you desire integration with helm
(with-eval-after-load 'helm-files
(su-helm-integration-mode +1))
# If you desire integration with semantic
(with-eval-after-load 'semantic/fw
(su-semantic-integration-mode +1))
When su-mode
is enabled, files you do not have permission to read but not write will remain editable (i.e. buffer-read-only
will be nil
) and su-mode
will indicate in the modeline that any changes made will require privilege escalation to save.
If you attempt to save your modifications, su-mode
switches the path the buffer is visiting to a TRAMP path to the same file specifying a user able to perform the write.
If a password is required, TRAMP will ask you to enter it, after which the file will be written.
The visitation switch is permanent so you will remain authenticated thereafter.
If you do not even have permission to read the file, then su.el
will switch the visited path immediately, allowing you to read it.
Significant effort has been made to ensure that su.el
operates correctly.
In particular:
- It can use either the
su
orsudo
methods to switch users and will automatically detect which one to use. - It works even if you are already using TRAMP (e.g. for editing a remote file) by adding another hop.
- It may even work with your custom TRAMP methods, although this cannot be guaranteed.