ssh通过原来的用户到服务器上的环境

首先,我不知道将信息传递给环境是最好的方法,所以我将首先详细介绍我实际上想要达到的目标。

在公司范围内,有一些服务器,其中一些雇员拥有单独的shell帐户,他们使用这些帐户连接到其他服务器,使用公钥authentication,以root身份login。

我想要做的就是能够告诉他们正在login的远程服务器,服务器上的用户帐户是从哪里来的。

例如用户John Doe,在central.server上有一个帐户,他login到他的帐户jdoejdoe用户现在连接到remote.server.1,并以公钥validation身份login。

我想logging他在remote.server.1上发出的命令,但是我想保留central.server上他实际上是jdoe的信息

所以,基本上我想能够从remote.server.1中取出一个日志,看看哪个员工在什么时间,什么地方做了什么

据我所知,我可以在remote.server.1的configuration文件或bashrc中添加一些日志logging,并使用PermitUserEnvironment设置sshd,在central.server上使用全局configuration文件,并使用它将环境variables中的用户名传递给远程。 server.1

我想知道是否有更好的方法来实现呢?

谢谢

第一个也是最好的解决scheme是不允许SSHlogin到root帐户。 正如你自己find的,这使得很难跟踪谁做了什么。 应该有权访问服务器的人应该使用自己的帐户,然后使用sudo执行需要root访问权限的任务。 这是SSH访问的最佳实践。

您可能还希望在用户进行SSH工作的中央服务器上设置审核日志logging。 您可以使用auditctl来仅loggingssh命令。 (虽然开启审计会降低服务器的速度,但是您需要进行一些性能评估,以确定它是否适用于您。)

您也可以将信息添加到目标服务器上的SSH密钥的公共部分 – 请参阅此问题的一些提示。 但是,由于用户拥有root用户,他们很容易修改这些数据,所以对于任何严重的审计都是不可用的。

另外,如果将LogLevel设置为VERBOSE ,则sshd将logging用于login的ssh密钥的指纹。 但是,除非这些日志被转发到这些人无法访问的远程服务器,否则可能会被篡改,从而不构成可靠的审计跟踪。

没有办法既保留审计function,又让用户成为根。

相反,授予sudo访问您的用户需要的命令,并logging一切。

sudoers(5)手册页:

  sudoers also supports logging a command's input and output streams. I/O logging is not on by default but can be enabled using the log_input and log_output Defaults flags as well as the LOG_INPUT and LOG_OUTPUT command tags. log_input If set, sudo will run the command in a pseudo tty and log all user input. If the standard input is not connected to the user's tty, due to I/O redirection or because the command is part of a pipeline, that input is also captured and stored in a separate log file. This flag is off by default. Input is logged to the directory specified by the iolog_dir option (/var/log/sudo-io by default) using a unique session ID that is included in the normal sudo log line, prefixed with “TSID=”. The iolog_file option may be used to con‐ trol the format of the session ID. Note that user input may contain sensitive information such as passwords (even if they are not echoed to the screen), which will be stored in the log file unencrypted. In most cases, logging the command output via log_output is all that is required. log_output If set, sudo will run the command in a pseudo tty and log all output that is sent to the screen, similar to the script(1) command. If the standard output or standard error is not connected to the user's tty, due to I/O redirection or because the command is part of a pipeline, that output is also captured and stored in separate log files. This flag is off by default. Output is logged to the directory specified by the iolog_dir option (/var/log/sudo-io by default) using a unique session ID that is included in the normal sudo log line, prefixed with “TSID=”. The iolog_file option may be used to con‐ trol the format of the session ID. Output logs may be viewed with the sudoreplay(8) utility, which can also be used to list or search the available logs. 

此外,您还想要loggingsudo使用情况:

  sudoers can log both successful and unsuccessful attempts (as well as errors) to syslog(3), a log file, or both. By default, sudoers will log via syslog(3) but this is changeable via the syslog and logfile Defaults settings. 

作为最后一点,您需要确保授予您的用户的访问权限不会授予太大的权限,以便允许他们覆盖审核系统。