[英]Making an app using ssh to shutdown macbook
I have been trying to create an app that can shutdown my mac using ssh.我一直在尝试创建一个可以使用 ssh 关闭我的 mac 的应用程序。 I've tried
ssh-copy-id -i ~/.ssh./id_rsa.pub ssh "my computer" | sudo shutdown -h now
我试过
ssh-copy-id -i ~/.ssh./id_rsa.pub ssh "my computer" | sudo shutdown -h now
ssh-copy-id -i ~/.ssh./id_rsa.pub ssh "my computer" | sudo shutdown -h now
but I get an error message saying zsh:exit 1
and zsh: suspended (tty output) sudo shutdown -h now
and I don't know what to do. ssh-copy-id -i ~/.ssh./id_rsa.pub ssh "my computer" | sudo shutdown -h now
但我收到一条错误消息说zsh:exit 1
和zsh: suspended (tty output) sudo shutdown -h now
我不知道该怎么做。
There are several issues with your command:您的命令有几个问题:
ssh-copy-id -i ~/.ssh./id_rsa.pub ssh "my computer" | sudo shutdown -h now
ssh-copy-id
needs the private key, but you've provided the public key ssh-copy-id
需要私钥,但您提供了公钥sudo shutdown -h now
locally rather than remotelysudo shutdown -h now
Run this just one time.只运行一次。 It will prompt you for your user's password on
mycomputer
:它会提示您在
mycomputer
上输入您的用户密码:
ssh-copy-id -i ~/.ssh/id_rsa mycomputer
Then you can run this:然后你可以运行这个:
ssh -t mycomputer "sudo shutdown -h now"
This will be interactive since you need to enter your user password for sudo
, but at least the key prevents you from needing to enter it a second time to gain access to the system.这将是交互式的,因为您需要输入
sudo
的用户密码,但至少该密钥可以防止您需要再次输入它来访问系统。
You could reduce this by allowing your user to run that command without a password.您可以通过允许您的用户在没有密码的情况下运行该命令来减少这种情况。 From a shell on that computer (
ssh mycomputer
), run visudo
(if the last line of that file looks like @includedir /etc/sudoers.d
, quit and run something like visudo -f /etc/sudoers.d/local
) and add this to the end:从该计算机上的 shell (
ssh mycomputer
) 运行visudo
(如果该文件的最后一行看起来像@includedir /etc/sudoers.d
,退出并运行类似visudo -f /etc/sudoers.d/local
的东西)将其添加到末尾:
gjwlsdnd224 ALL=(root) NOPASSWD: /sbin/shutdown -h now
where gjwlsdnd224
is your username.其中
gjwlsdnd224
是您的用户名。 If you do this, you don't need -t
passed to ssh
.如果你这样做,你不需要
-t
传递给ssh
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.