【问题标题】:Applescript confirm sudo password in ssh connectionApplescript 在 ssh 连接中确认 sudo 密码
【发布时间】:2015-01-31 15:16:10
【问题描述】:

我正在使用 applescript 打开与 Ubuntu Box 的 ssh 连接。如何提供 apt 询问的 sudoer 密码:

tell application "Terminal"
        set currentTab to do script ("ssh -p" & pnumber & " " & user & "@localhost;")
        delay 2
        do script ("sudo apt-get update") in currentTab

        -- start provide here password for sudo
        -- this ends in keystroke cannot be read
        keystroke "password"
        keystroke return
        -- end provide password

        do script ("exit;") in currentTab
    end tell

【问题讨论】:

标签: applescript


【解决方案1】:
try
    set resultText to (do shell script "apt-get update" with administrator privileges)
on error e number n 
    tell application (path to frontmost application as text )
        display alert "Something went wrong: " & e & " nr: " & n
    end tell
    error number -128
end try
tell application (path to frontmost application as text)
    display alert resultText
end tell

您必须在 do shell 脚本中添加 apt-get 的完整路径。如果你坚持要在终端运行,那你就得写一个expect脚本了。

【讨论】:

    【解决方案2】:

    不需要密码。设置一个安全的 RSA 密钥,您将永远不必再这样做。然后您的 Applescript 将无需密码即可运行。

    https://help.ubuntu.com/community/SSH/OpenSSH/Keys

    【讨论】:

    • 当然,但在某些情况下您无法更改服务器身份验证;)
    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    相关资源
    最近更新 更多