sshfs 在期望脚本中不使用密码

发布于 2024-11-30 21:18:30 字数 1899 浏览 1 评论 0原文

我编写了一个小脚本来向 sshfs 提供密码,但由于某种原因 sshfs 没有获取密码。有什么指点吗? (PS,我知道 ssh 密钥更好/更安全,但我工作的政治环境阻止在目标服务器上设置基于密钥的身份验证 - 叹息......)。

#!/usr/bin/expect
# NOT WORKING!!
exp_internal 1
spawn sshfs server:/export/pc_storage /home/sonia/mnt/server
expect {
    "assword:" {
        send "secret\r\r"
        send_user "\n"
    }
    timeout {
        send_user "timed out!\n"
     }
}

为了终止密码,我尝试了 \r \n \r\r - 没有效果。

调试输出,显示密码提示正在触发:

spawn sshfs server:/export/pc_storage /home/sonia/mnt/server
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {17532}

expect: does "" (spawn_id exp6) match glob pattern "assword:"? no
pcuser@server's password: 
expect: does "pcuser@server's password: " (spawn_id exp6) match glob pattern "assword:"? yes
expect: set expect_out(0,string) "assword:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "pcuser@server's password:"
send: sending "secret\r\r" to { exp6 }

% uname -a
Linux zapote 2.6.38-10-generic-pae #46-Ubuntu SMP Tue Jun 28 16:54:49 UTC 2011 i686 i686 i386 GNU/Linux

% sshfs -V
SSHFS version 2.2
FUSE library version: 2.8.4
fusermount version: 2.8.4
using FUSE kernel interface version 7.12

已解决:(

我无法发布答案,因为我没有 100 分 - 双重叹息)

我需要稍微修复一下...例如,我将 PS1 硬编码为我的 .bashrc 为“bash_prompt”(我默认使用 zsh)。

#!/usr/bin/expect

# FIX: get homedir from env, set bash prompt somehow...

set timeout 30

spawn /bin/bash
expect "bash_prompt"
send_user "Shell spawned.\n"

send -- "sudo umount /home/sonia/mnt/server &> /dev/null\r"
expect "bash_prompt"

send -- "sshfs server:/export/pc_storage /home/sonia/mnt/server\r"
expect {
    "assword:" {
        send "secret\r"
        send_user "\n"
    }
    timeout {
        send_user "timed out!\n"
    }
}
expect "bash_prompt"

I've written a little script to supply a password to sshfs, but for some reason sshfs isn't grabbing the password. Any pointers? (PS I know ssh keys are better/safer, but politics where I work prevents key based authentication being setup on the target server - sigh... ).

#!/usr/bin/expect
# NOT WORKING!!
exp_internal 1
spawn sshfs server:/export/pc_storage /home/sonia/mnt/server
expect {
    "assword:" {
        send "secret\r\r"
        send_user "\n"
    }
    timeout {
        send_user "timed out!\n"
     }
}

To terminate the password, I've tried \r \n \r\r - none work.

Debugging output, showing that password prompt is triggering:

spawn sshfs server:/export/pc_storage /home/sonia/mnt/server
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {17532}

expect: does "" (spawn_id exp6) match glob pattern "assword:"? no
pcuser@server's password: 
expect: does "pcuser@server's password: " (spawn_id exp6) match glob pattern "assword:"? yes
expect: set expect_out(0,string) "assword:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "pcuser@server's password:"
send: sending "secret\r\r" to { exp6 }

% uname -a
Linux zapote 2.6.38-10-generic-pae #46-Ubuntu SMP Tue Jun 28 16:54:49 UTC 2011 i686 i686 i386 GNU/Linux

% sshfs -V
SSHFS version 2.2
FUSE library version: 2.8.4
fusermount version: 2.8.4
using FUSE kernel interface version 7.12

SOLVED:

(I can't post an answer as I don't have 100 points - double sigh)

I need to fix this up a bit... For example I hard coded PS1 in my .bashrc to "bash_prompt" (I use zsh by default).

#!/usr/bin/expect

# FIX: get homedir from env, set bash prompt somehow...

set timeout 30

spawn /bin/bash
expect "bash_prompt"
send_user "Shell spawned.\n"

send -- "sudo umount /home/sonia/mnt/server &> /dev/null\r"
expect "bash_prompt"

send -- "sshfs server:/export/pc_storage /home/sonia/mnt/server\r"
expect {
    "assword:" {
        send "secret\r"
        send_user "\n"
    }
    timeout {
        send_user "timed out!\n"
    }
}
expect "bash_prompt"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋千易 2024-12-07 21:18:30

您可以直接提供密码,而不是使用 Expect。
尝试一下:

echo your-password | sshfs server:/export/pc_storage /home/sonia/mnt/server -o password_stdin

不确定您是否可以使用您的密码策略来实现此功能,但值得一试。

Rather than use Expect, you can just supply the password directly.
Try this:

echo your-password | sshfs server:/export/pc_storage /home/sonia/mnt/server -o password_stdin

Not sure if you can make this work with your password policies, but its worth a shot.

望她远 2024-12-07 21:18:30

我需要稍微修复一下这个问题...例如,我将 .bashrc 中的 PS1 硬编码为“bash_prompt”(默认情况下我使用 zsh)。

#!/usr/bin/expect

# FIX: get homedir from env, set bash prompt somehow...

set timeout 30

spawn /bin/bash
expect "bash_prompt"
send_user "Shell spawned.\n"

send -- "sudo umount /home/sonia/mnt/server &> /dev/null\r"
expect "bash_prompt"

send -- "sshfs server:/export/pc_storage /home/sonia/mnt/server\r"
expect {
    "assword:" {
        send "secret\r"
        send_user "\n"
    }
    timeout {
        send_user "timed out!\n"
    }
}
expect "bash_prompt"

I need to fix this up a bit... For example I hard coded PS1 in my .bashrc to "bash_prompt" (I use zsh by default).

#!/usr/bin/expect

# FIX: get homedir from env, set bash prompt somehow...

set timeout 30

spawn /bin/bash
expect "bash_prompt"
send_user "Shell spawned.\n"

send -- "sudo umount /home/sonia/mnt/server &> /dev/null\r"
expect "bash_prompt"

send -- "sshfs server:/export/pc_storage /home/sonia/mnt/server\r"
expect {
    "assword:" {
        send "secret\r"
        send_user "\n"
    }
    timeout {
        send_user "timed out!\n"
    }
}
expect "bash_prompt"
伊面 2024-12-07 21:18:30

\r\r 似乎不对。您尝试过\r\n吗?

\r\r does not seem right. Have you tried \r\n?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文