zoukankan      html  css  js  c++  java
  • pssh 不能执行指定用户命令

    问题:

        一个脚本a.sh(必须root用户执行),在本地可以运行,通过pssh  -h ip_file "cd /home/byte/a.sh"不能执行。

    原因:

      分析应该是ssh没有获取到root权限,可能原因是操作系统安装时有多个用户且默认远程用户非root。通过查看可知是ssh默认登录用户不是root

      Linux系统设置涉及到两种启动shell的方式一个是本地登录另一个是远程登录,

      本地直接登录shell终端环境调用过程是 ~/.bash_profile->~/.bashrc

      ssh登录时直接调用~/.bashrc,导致只是以普通用户登录,没有获取到root权限

    解决办法:

    1.修改命令,先执行root的.bash_profile来获取root权限

       pssh  -h ip_file "source  /root/.bash_profile;cd /home/byte/a.sh"

    2.修改.ssh配置文件

      vi /etc/.ssh/enviroment 添加所需环境变量,格式如下

      VAR1=VALUE1

      VAR2=VALUE2

    比如添加 USER=root

     并修改/etc/ssh/sshd_config 文件中的PermitUserEnvironment=yes(会带来安全问题,具体请看备注1链接)

    下次登录就直接获取root权限了

    备注:

    1. 安全问题 

    PermitUserEnvironment
                 指定是否允许 sshd(8) 处理 ~/.ssh/environment 以及 ~/.ssh/authorized_keys 中的 environment= 选项。
     
    默认值是"no"。如果设为"yes"可能会导致用户有机会使用某些机制(比如 LD_PRELOAD)绕过访问控

    参考连接 http://www.2cto.com/os/201401/272738.html
    http://serverfault.com/questions/527638/security-risks-of-permituserenvironment-in-ssh
    2.相关文件解释
    /bin/bash The bash executable /etc/profile The systemwide initialization file, executed for login shells ~/.bash_profile The personal initialization file, executed for login shells ~/.bashrc The individual per-interactive-shell startup file ~/.bash_logout The individual login shell cleanup file, executed when a login shell exits ~/.inputrc Individual readline initialization file

    参考:http://serverfault.com/questions/527638/security-risks-of-permituserenvironment-in-ssh

           http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment

  • 相关阅读:
    Linux下hook指定库
    一行一行往上爬
    高可用数据同步方案-SqlServer迁移Mysql实战
    Hystrix核心基础
    Fastjson解析多级泛型的几种方式—使用class文件来解析多级泛型
    面试大全之JVM篇
    云原生下的CICD
    学习Raft算法的笔记
    Go语言下的线程模型
    分布式事务解决方案以及 .Net Core 下的实现(上)
  • 原文地址:https://www.cnblogs.com/ibyte/p/6164094.html
Copyright © 2011-2022 走看看