Applescript confirm sudo password in ssh connection

拜拜、爱过 提交于 2019-12-12 03:23:58

问题


I´m opening a ssh connection to an Ubuntu Box with applescript. How can I provide the sudoer password asked by apt:

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

回答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

You'll have to add the full path to apt-get in the do shell script. If you insist of running it in the terminal, then you'll have to write an expect script.




回答2:


No need for password. Setup a secure RSA key and you will never have to do it again. Then your Applescript will run without a password.

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



来源:https://stackoverflow.com/questions/28253149/applescript-confirm-sudo-password-in-ssh-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!