ssh auto login, but user control after
Here is the story. I have a Debian 5 server automatically starting into a local user account. The local user account has the following .profile
#!/bin/bash
SERVERPASS="password"
function with_password {
expect << END
set timeout 900
spawn $2
expect *assword:*
send -- "${1}\r"
expect EOF
exit 0
END
}
cd /home/timecard
with_password $SERVER开发者_如何学运维PASS "ssh timecard@192.168.254.5 -p 22"
This then connects to the remote computer as user timecard.
However the issue is that I cannot interact normally with it. When I type, the text does not stay within my program on the remote computer.
When I connect manually however, it works just fine.
So how do I mimic the manual login to the server using the expect command? Am I missing a command?
P.S. Yes I know automatic logins are bad, I know that ssh autologin is bad, etc...
The problem here is the expect EOF
, I think. This means your expect call only will return when you already logged off, so you can't send any keys to this.
Does the same work without this line?
But of course, use public-key authentication instead of automatic password login.
The following expect script works for me with ssh (I don't have password authentication enabled, so I'm using the "do you want to allow the host key" question instead):
#!/usr/bin/expect -f
system ssh-keygen -R localhost
spawn ssh -o StrictHostKeyChecking=ask localhost
expect "(yes/no)? "
send -- "yes\n"
interact
精彩评论