http://bald.cat

emacs and sudo

To edit files as an other user, emacs utilizes tramp's multi-hop filenames to create an intermediate checkpoint; the path is translated in the same manner as if it was going through an ssh proxy connection.

This works the same even with org-mode's :dir option during code block execution; the syntax there is /sudo:: - the double colons representing a missing argument, to be filled with the current proxy defaults. Proxies are cached in tramp-default-proxies-alist, or can be added manually.

(add-to-list 'tramp-default-proxies-alist
	     ;;  host      user   proxy
	     '(("baldcat" "root" "/ssh:baldcat:")))

On a remote machine, the proxy should be specified, as this ensures that the local environment is not used to determine any missing properties. To log in before running the sudo command for the user root - note the use of the | (pipe) character for each new proxy;

/ssh:baldcat|sudo:baldcat:/etc/rc.conf

login prompts

A side effect of using tramp is that it utilizes eshell to parse the ssh connection; which includes parsing command prompts, which can vary from server to server.

When tramp seems to just hang, or not accept a proper password, it is likely that it is finding the remote prompt confusing; this is not likely to be a problem locally. The PS1 environment variable can be declared in a number of places on the remote host; /etc/profile, ~/.bash_profile for example. Use the simplest decleration possible - the other option is editing tramp's prompt regexp.

export PS1="\[\033[1m\]\\$ \[\033[0m\]" # Crux's default
export PS1=">"

disconnecting

(tramp-cleanup-all-connections)

2018 - Élő László hello at bald dot cat