LoginSignup
10
9

More than 5 years have passed since last update.

Emacs Tramp Mode使い方(port指定+sudo権限)

Last updated at Posted at 2017-03-20

正直よくわかっていないが,どうやらemacsにはtramp-modeという
remote server上のファイルをlocalで(にあるかのように)編集できる機能
があるらしいので,さっそく試してみた.

いくつかつまづいたポイントがあるので,メモ書き程度に残しておく.

使い方

C-x C-f /ssh:user1@hostname1:path/to/file
でremoteにあるファイルにアクセスできる

以下はそのときの~/.ssh/config

host user
     HostName hostname1
     User user1

Portの指定

ここがちょっとつまづいたところ.
port番号を指定してsshする場合などはこれが必要になる.
C-x C-f /ssh:user2@hostname2#22:path/to/file
HostNameのあとにport番号(#22)を指定するのがミソ

以下はそのときの~/.ssh/config

host user
     HostName hostname2
     User user2
     Port 22

sudo権限で実行

ここがさらにつまづいたところ.
例えば,/etc/以下のファイルなどをいじるときはこれが必要になる.
C-x C-f /ssh:user3@hostname3|sudo:hostname3:path/to/file
|sudo:hostname3がミソ

port指定+sudo権限

最終的に,自分のsudo権限が必要なファイルにport番号指定してアクセスするのは,
C-x C-f /ssh:user4@hostname4#44|sudo:hostname4:path/to/file
でいける.

以下はそのときの~/.ssh/config

host user
     HostName hostname4
     User user4
     Port 44

参考にさせていただいた記事

Tramp でポート指定する方法
[Emacs] tramp-modeが便利

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9