Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:40:35+00:00 2026-06-03T14:40:35+00:00

Several questions, including this one, discuss aspects relating to ssh connections from within Emacs.

  • 0

Several questions, including this one, discuss aspects relating to ssh connections from within Emacs. I haven’t found an answer to my question though: How can I ssh into a remote machine from within Emacs?

I do not wish to edit a file on the remote machine from within Emacs. I am aware of M-x shell which opens a shell on my local machine and I am aware of using TRAMP to edit a file over ssh on the remote machine. However, neither of these relate to this question.

(Instead of voting to close, maybe migrate the question to another site.)

Edit: Related discussion here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:40:37+00:00Added an answer on June 3, 2026 at 2:40 pm

    Firstly, I am unaware of a native elisp ssh client (and do not imagine there is a great deal of motivation for writing one), so you will certainly need to interact with an external ssh client process.

    As you wish to use ssh interactively, the ssh process requires a terminal on the local side of the connection.

    The question therefore becomes: Does Emacs implement a terminal to which an ssh process can be attached?

    The answer is: yes — term.el provides a robust terminal implementation, through which ssh can be run directly, without the requirement for a shell.

    If you run M-x term RET you will be prompted for a program. (It defaults to a shell, but that is certainly not the only type of process you can run.)

    For reasons unknown, the interactive term (and ansi-term) functions do not support passing arguments to the specified program, which renders them less useful if you wished to run something like ssh user@host. You could instead specify a script which handled the arguments, but we can manage that in elisp as well:

    The term function is actually a simple wrapper which calls make-term to start the program and then sets the appropriate modes. As make-term does accept program arguments, it is quite straightforward to copy-and-modify the definition of term to suit your own purposes.

    Here is a very simple implementation:

    (defun my-ssh (user host port)
      "Connect to a remote host by SSH."
      (interactive "sUser: \nsHost: \nsPort (default 22): ")
      (let* ((port (if (equal port "") "22" port))
             (switches (list host "-l" user "-p" port)))
        (set-buffer (apply 'make-term "ssh" "ssh" nil switches))
        (term-mode)
        (term-char-mode)
        (switch-to-buffer "*ssh*")))
    

    or perhaps this is preferable:

    (defun my-ssh (args)
      "Connect to a remote host by SSH."
      (interactive "sssh ")
      (let ((switches (split-string-and-unquote args)))
        (set-buffer (apply 'make-term "ssh" "ssh" nil switches))
        (term-mode)
        (term-char-mode)
        (switch-to-buffer "*ssh*")))
    

    Obviously there is scope for improvements, but I think that’s fairly useful as-is.

    You should ensure that you are familiar with the quirks of term-mode. See:

    • M-: (info "(emacs) Terminal emulator") RET
    • M-: (info "(emacs) Terminal Mode") RET
    • C-hf term-mode RET
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are several old (around 2009) questions on SO addressing this issue, for example:
There have been several questions posted to SO about floating-point representation. For example, the
There have been several questions over the past few days about the proper use
I have several questions: 1. What's the difference between isoMDS and cmdscale? 2. May
I have several questions regarding filenames and the iPod Library. I understand I can
After reading several questions regarding problems with compilation (particularly C++) and noticing that in
I have seen several questions with people asking about the same problem but none
I've seen several questions/answers related to entirely creating a button in code, but not
I've read several questions here concerning Tomcat and logging but I still really don't
I've looked at several questions here that looked similar, but none of them discussed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.