TRAMP로 접속 후 유저를 변경 후 파일을 열고 싶다면

less than 1 minute read

vagrant@ubuntu-xenial:~$ sudo su root
root@ubuntu-xenial:/home/vagrant# ls -la hello
-rw-r--r-- 1 root root 6 Mar 23 23:29 hello
root@ubuntu-xenial:/home/vagrant# exit
vagrant@ubuntu-xenial:~$ cat hello
world
vagrant@ubuntu-xenial:~$ >hello echo "tramp"
-bash: hello: Permission denied
vagrant@ubuntu-xenial:~$ cat hello
world

vagrant로 linux 가상 머신을 만들어서 root 유저로 hello 파일을 만들었다. vagrant가 만든 vagrant 유저는 hello 파일을 볼 수만 있을 뿐 수정할 순 없다.

<TRAMP로 원격 파일을 로컬 파일처럼 편집> 글에서 설명한 방법으로 hello 파일을 emacs 버퍼로 열면 읽을 수만 있을 뿐 수정할 순 없다. tramp 패키지를 사용해서 root 유저로 hello 파일을 열 수 있을까?

C-x C-f /ssh:default|sudo:root@default:/home/vagrant/hello

파일 이름에 유저 변경 명령을 넣으면 된다.

| 문자로 홉(hop)을 여러 개 붙일 수 있다. ssh:default 명령으로 default 호스트에 연결한 다음 sudo:root@default:/home/vagrant/hello 명령으로 root 유저로 hello 파일을 연다.

이제 유저 변경이 필요할 때도 tramp로 열어서 편집하면 된다.

참고

C-x C-s C-x C-c