用户创build的MOTD阻止SCP运行

我已经创build了自定义MOTD,通过执行以下操作在login时显示:

  1. /etc/usermotd/<username>里面创build一个文本文件
  2. 编辑用户的.bashrc文件,并把下面的代码:
 if [ -f /etc/usermotd/`whoami` ]; then cat /etc/usermotd/<username>; fi 

它像我想要的那样工作。 然而…

我现在刚刚发现,当我尝试SCP的时候,这是行不通的。 我做了scp命令,退出时没有给出任何进度条或者说它已经转移。 当我做scp -vvv时,我得到了

 debug1: Authentication succeeded (publickey). debug2: fd 4 setting O_NONBLOCK debug2: fd 5 setting O_NONBLOCK debug1: channel 0: new [client-session] debug3: ssh_session2_open: channel_new: 0 debug2: channel 0: send open debug1: Requesting [email protected] debug1: Entering interactive session. debug2: callback start debug2: client_session2_setup: id 0 debug1: Sending command: scp -v -t ~ debug2: channel 0: request exec confirm 1 debug2: fd 3 setting TCP_NODELAY debug2: callback done debug2: channel 0: open confirm rwindow 0 rmax 32768 debug2: channel 0: rcvd adjust 2097152 debug2: channel_input_status_confirm: type 99 id 0 debug2: exec request accepted on channel 0 WELCOME debug2: channel 0: read<=0 rfd 4 len 0 debug2: channel 0: read failed debug2: channel 0: close_read debug2: channel 0: input open -> drain debug2: channel 0: ibuf empty debug2: channel 0: send eof debug2: channel 0: input drain -> closed BigBoss ~/.ssh:-$ debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug2: channel 0: rcvd eof debug2: channel 0: output open -> drain debug2: channel 0: obuf empty debug2: channel 0: close_write debug2: channel 0: output drain -> closed debug2: channel 0: rcvd close debug3: channel 0: will not send data after close debug2: channel 0: almost dead debug2: channel 0: gc: notify user debug2: channel 0: gc: user detached debug2: channel 0: send close debug2: channel 0: is dead debug2: channel 0: garbage collecting debug1: channel 0: free: client-session, nchannels 1 debug3: channel 0: status: The following connections are open: #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cfd -1) debug3: channel 0: close_fds r -1 w -1 e 6 c -1 debug1: fd 0 clearing O_NONBLOCK debug1: fd 1 clearing O_NONBLOCK Transferred: sent 2208, received 3352 bytes, in 0.2 seconds Bytes per second: sent 13207.5, received 20050.5 debug1: Exit status 0 

任何想法为什么它没有发送? 或者有另一种方法可以做到这一点?

它没有工作,因为scp希望远程端行为正好“这样”,而不是尖叫欢迎回来。 (这是很好,如果它会给出一个错误信息,但是…)。

使用sftp (根本不生成loginshell)而不是scp或者让你的.bashrc检测它是否在交互式会话中。 似乎有几个方法来做到这一点:

 if [ -n "$PS1" ]; then echo WELCOME fi; 

在那里给出的另一种方法,看看是否“$ – ”包含“我”似乎被打破,因为[不做*在string比较。 这应该工作,虽然(它检查,以确保$ – 被设置,然后检查,看看$ – 与“我”删除是相同的$ – 。也许有更好的办法,但我想不到在第二)

 if [ -n "$-" -a "${-/i}" != "$-" ]; then echo WELCOME fi; 

如果您希望scp正常工作,则不能生成terminal输出。 你所要做的就是将任何输出生成的东西包括在.cshrc中,如下所示:

  if ($?prompt != 0) then cat /etc/motd endif 

因此,如果有一个terminal接收它(即一个SSHlogin),你只能产生输出。