non-login/login/interactive/non-interactive关系

本文介绍如何创建一个名为'safe-remote-poweroff'的脚本,当root用户尝试使用'poweroff'命令时,防止意外关闭远程Linux机器。脚本会在实际执行关机命令之前检查连接是否为远程,如果是远程连接,则显示警告并提供正确关机的指导。
摘要由CSDN通过智能技术生成

https://classpage.dmorgan.us/linadmin/labs/safe-remote-poweroff/safe-remote-poweroff.htm

safe remote poweroff

If you run a root command shell on your linux machine and remotely administer another one, also via a root command shell, it’s a matter of time before you power off the local one only to discover that, oops, no, you just shut down the remote instead by accident. At that point a remote physical presence is needed, to press the power button. Get in the car, or buy your plane ticket, or embarrass yourself with another phone call to somebody onsite asking them to again fix your mistake for you. Or, you could write some substitute prophylactic code under the same name(s) as the command(s) you habitually use for turning the machine off (probably shutdown, poweroff, or halt). Write it so it deflects (does not actually run) the poweroff attempt, instead printing a helpfully alarmist message reminding the adminstrator that OMG he appears to be trying to turn off the remote machine, telling him how to do so if it’s what he actually intended, and exiting. Never again will he do it unawares.

Let’s assume the command you always use to put your machines down is poweroff. There is probably more than one solution. But any of them will involve emplacing some code that goes by the name “poweroff” and gets called ahead of the usual code that actually turns out the lights, eclipsing it. The new code will not turn the machine off, but rather print a message saying so and giving the user an alternative direct command that will run the regular poweroff. Except, that’s a bit of overkill if done unconditionally. You really want to take that step only in case of a remote connection. If “poweroff” is issued on a local one, you want to let it go through. It’s OK, the protection is unneeded, because turning off the machine by accident is recoverable by just turning it right back on again. By contrast a remote user doesn’t have that luxury; so the new code should be conditional on whether the user’s connection is local or remote.

The assignment to perform:

Operate as root. Write a script to be run in whenever the root user ty

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值