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 793315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:07:55+00:00 2026-05-14T22:07:55+00:00

So I wanted to automate my SSH logins. The host I’m with doesn’t allow

  • 0

So I wanted to automate my SSH logins. The host I’m with doesn’t allow key authentication on this server, so I had to be more inventive.

I don’t know much about shell scripting, but some research showed me the command ‘expect’ and some scripts using it for exactly this purpose. I set up a script and ran it, it worked perfectly to login.

#!/usr/bin/env expect -f

set password "my_password"

match_max 1000

spawn ssh -p 2222 "my_username"@11.22.11.22

expect "*?assword:*"
send -- "$password\r"
send -- "\r"

expect eof

Initially, it runs as it should.

Last login: Wed May 12 21:07:52 on ttys002
esther:~ user$ expect expect-test.exp
spawn ssh -p 2222 my_username@11.22.11.22
my_username@11.22.11.22's password: 
Last login: Wed May 12 15:44:43 2010 from 20.10.20.10


-jailshell-3.2$ 

But that’s where the success ends.

Commands do not work, but hitting enter just makes a new line.
Arrow keys and other non-alphanumeric keys produce symbols like ‘^[[C’, ‘^[[A’, ‘^[OQ’ etc.[1]

No other prompt appears except the two initially created by the expect script.
Any ignored commands will be executed by my local shell once expect times out.
An example:

-jailshell-3.2$ whoami
ls
pwd
hostname

(…time passes, expect times out…)

esther:~ user$ whoami
user

esther:~ ciaran$ ls
Books       Documents   Movies      Public      
Code        Downloads   Music       Sites       
Desktop     Library     Pictures    expect-test.exp

esther:~ ciaran$ pwd
/Users/ciaran

esther:~ ciaran$ hostname
esther.local

As I said, I have no shell scripting experience, but I think it’s being caused because I’m still “inside of” expect, but not “inside of” SSH. Is there any way to terminate expect once I’ve logged in, and have it hand over the SSH session to me?

I’ve tried commands like ‘close’ and ‘exit’, after ” send — “\r” “. Yeah, they do what I want and expect dies, but it vindictively takes the SSH session down with it, leaving me back where I started. What I really need is for expect to do its job and terminate, leaving the SSH session back in my hands as if I did it manually.

All help is appreciated, thanks.
[1] I know there’s a name for this, but I don’t know what it is. And this is one of those frightening things which can’t be googled, because the punctuation characters are ignored. As a side question, what’s the story 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-05-14T22:07:56+00:00Added an answer on May 14, 2026 at 10:07 pm

    I think your problem has been solved here before:

    Using expect to pass a password to ssh

    The command you’re looking for is interact. It hands the control over to you/your keyboard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to automate ssh logins. After some research, it seemed like tcl/expect was
Wanted to know if someone had a suggestion on code or maybe there's a
I just wanted a more elegant automated solution to my form validation. On PHP.net
I'm beginning to learn twisted.conch to automate some tasks over SSH. I tried to
Update: 24 Mar 2011: Just wanted to add that I've had a look at
For a while I have wanted to automate the setup of several redirects for
I currently have a script to help me automate an install. During this install
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>
Wanted to get some consensus around a UI feature I'm working on right now.
Wanted to see if anyone knows how to add props to a image with

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.