1

I normally connect to another server using the terminal using:

ssh username@xx.xx.xx.xx

However, I have been using emacs a lot now, and I am wondering if I can connect to a remote Red Hat server from within emacs?

Many thanks for any suggestions,

ire_and_curses
  • 68,372
  • 23
  • 116
  • 141
ant2009
  • 27,094
  • 154
  • 411
  • 609

4 Answers4

8

Tramp mode is your friend. Install it, then use

C-x f RETURN /xx.xx.xx.xx.:~username/some/dir/somefile.txt

and the file will open in your local session. Emacs and Tramp will sync all updates due to your local editing back to the server.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 4
    @ant2009: Why did you accept this answer? You wanted to connect to a remote server via SSH from within Emacs, not open/edit a file on a remote server in Emacs. – SabreWolfy May 09 '11 at 08:11
3

I'm a fan of ansi-term-mode (so M-x ansi-term) as a varient which provides a more usefull terminal emulation environment.

Tramp mode, as stated by Dirk is great for editing files, particularly if your connection is fast enough, but if you just need to toggle between a terminal and a buffer quickly, using ansi-term or term or shell all work fine. Particularly if your window manager doesn't support this toggling on a window manager level.

For a lot of things, I just have little bash scripts that I execute with (shell-command "/path/to/shell/script") and they use ssh conventionally. Seems to take care of a lot of the whole "deployment/rsync push" workflow.

tychoish
  • 661
  • 4
  • 7
1

If you're interested in running general shell commands and not just editing remote files, take a look at shell-mode. After starting it with M-x shell, you'll get a shell running in a buffer. You can interact with the shell input and output like you would text in any other buffer.

Within shell-mode, you'll be able to run ssh and connect to your remote server just as you would outside emacs.

ataylor
  • 64,891
  • 24
  • 161
  • 189
  • I prefer M-x term for ssh sessions since it allows you to run interactive shell commands like, ahum, vi, less etc. But as stated by Dirk "tramp mode is your friend". – remvee Nov 03 '09 at 20:26
0

In emacs, to ssh to a system to run commands and also edit remote files see ssh.el in http://www.emacswiki.org/emacs/SshWithEmacs

  • 2
    Your comment is a tad abreviated. Please expand it so that everyone can understand it withut going to the link. – Rohit Gupta Jul 03 '15 at 00:04
  • I don't have enough points to add a GIF to my comment, so I provided the full explanation at emacswiki. I'll return to this when I have more points. – Bruce Wong Jul 04 '15 at 00:54