把scp的标准输出和标准错误都重定向到一个文件,为什么shell界面还能打出"Enter windows password:"的字符串呢?
scp fromfilename username@x.x.x.x:/topath/tofilename 2>&1 > /tmp/tmp.txt
Enter windows password:
查了openssh的代码,答案很明显了。
char *
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
{
ssize_t nr;
int input, output, save_errno;
char ch, *p, *end;
struct termios term, oterm;
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
struct sigaction savetstp, savettin, savettou, savepipe;
/* I suppose we could alloc on demand in this case (XXX). */
if (bufsiz == 0) {
errno = EINVAL;
return(NULL);
}
restart:
signo = 0;
/*
* Read and write to /dev/tty if available. If not, read from
* stdin and write to stderr unless a tty is required.
*/
if ((flags & RPP_STDIN) ||
(input = output = open(_PATH_TTY, O_RDWR)) == -1) {
if (flags & RPP_REQUIRE_TTY) {
errno = ENOTTY;
return(NULL);
}
input = STDIN_FILENO;
output = STDERR_FILENO;
}
/*
* Catch signals that would otherwise cause the user to end
* up with echo turned off in the shell. Don't worry about
* things like SIGXCPU and SIGVTALRM for now.
*/
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0; /* don't restart system calls */
sa.sa_handler = handler;
(void)sigaction(SIGALRM, &sa, &savealrm);
(void)sigaction(SIGHUP, &sa, &savehup);
(void)sigaction(SIGINT, &sa, &saveint);
(void)sigaction(SIGPIPE, &sa, &savepipe);
(void)sigaction(SIGQUIT, &sa, &savequit);
(void)sigaction(SIGTERM, &sa, &saveterm);
(void)sigaction(SIGTSTP, &sa, &savetstp);
(void)sigaction(SIGTTIN, &sa, &savettin);
(void)sigaction(SIGTTOU, &sa, &savettou);
/* Turn off echo if possible. */
if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
memcpy(&term, &oterm, sizeof(term));
if (!(flags & RPP_ECHO_ON))
term.c_lflag &= ~(ECHO | ECHONL);
#ifdef VSTATUS
if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
#endif
(void)tcsetattr(input, _T_FLUSH, &term);
} else {
memset(&term, 0, sizeof(term));
term.c_lflag |= ECHO;
memset(&oterm, 0, sizeof(oterm));
oterm.c_lflag |= ECHO;
}
if (!(flags & RPP_STDIN))
(void)write(output, prompt, strlen(prompt));
end = buf + bufsiz - 1;
for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
if (p < end) {
if ((flags & RPP_SEVENBIT))
ch &= 0x7f;
if (isalpha(ch)) {
if ((flags & RPP_FORCELOWER))
ch = tolower(ch);
if ((flags & RPP_FORCEUPPER))
ch = toupper(ch);
}
*p++ = ch;
}
}
scp会运行一个ssh子进程来完成连接鉴权.
13996 root 0:00 /usr/local/bin/ssh -x -oForwardAgent no -oPermitLocalCommand no -oClearAllForwardings yes -lusername x.x.x.x scp -t /topath/tofilename
root@444444[]:/proc/13996/fd> ls -lrt
total 0
lrwx------ 1 root root 64 Jan 4 04:12 9 -> /tmp/lock/lock9997
lrwx------ 1 root root 64 Jan 4 04:12 6 -> /dev/tty
lrwx------ 1 root root 64 Jan 4 04:12 5 -> socket:[158339]
lrwx------ 1 root root 64 Jan 4 04:12 4 -> socket:[158338]
lrwx------ 1 root root 64 Jan 4 04:12 3 -> socket:[160359]
lrwx------ 1 root root 64 Jan 4 04:12 2 -> /dev/pts/0
l-wx------ 1 root root 64 Jan 4 04:12 1 -> pipe:[160353]
lr-x------ 1 root root 64 Jan 4 04:12 0 -> pipe:[160352]
从此可知,ssh就是通过file descriptor 6直接写/dev/tty来把prompt显示到shell界面的,和标准输出1/标准错误2没有任何关系。
lrwx------ 1 root root 64 Jan 4 04:12 6 -> /dev/tty
分享到:
相关推荐
通过秘钥实现scp不输入密码传送文件,作成脚本可以实现远程备份等等实用功能.
pscp.exe windows下的scp命令,Windows与Linux之间传输文件的工具。 PSCP (PuTTY Secure Copy client)是PuTTY 提供的文件传输工具,通过SSH连接,在两台机器之间安全的传输文件,可以用于任何SSH(包括SSH v1、SSH ...
scp传输不输入密码
使用ssh、scp不需要密码。刚好项目遇到这个问题,学学挺好的。
java调SCP java调SCP.rarjava调SCP.rar
前言 scp是 secure copy的缩写, scp是Linux系统下...-B: 使用批处理模式(传输过程中不询问传输口令或短语) -C: 允许压缩。(将-C标志传递给ssh,从而打开压缩功能) -p:保留原文件的修改时间,访问时间和访问权限
Mac版本的scp图形界面的工具Fugo,绝对必备
不需要远程传输文件Linux如何关闭scp和sftp命令.docx
GP2.2-SCP03安全通道协议
1.scp 代码结构 1.1 scp 目录结构 2 scp module 2.1.所有module信息的维护 2.2.module功能的提供 2.2.1 module的绑定 3.scp 应用初始化及boot流程 3.1 scp 应用初始化流程 3.2 scp boot 3.2.1 ARM Trusted Firmware ...
java scp实现方式
Linux下scp的用法 scp就是secure copy,一个在linux下用来进行远程拷贝文件的命令。 有时我们需要获得远程服务器上的某个文件,该服务器既没有配置ftp服务器,也没有做共享,无法通过常规途径获得文件时,只需要通过...
SSH-SCP使用方法 ,如何不使用密码在服务器之间传输文件
中国物流行业scp分析及未来发展趋势-产业分析报告格式
温度气压传感器SCP1000英文资料,SCP1000-D01 AND SCP100-D11
SCP03基于AES算法的安全通道协议,通过安全域持有的密钥实现终端与Smart Card的安全通讯
Solarwinds的SCP/SFTP 服务器软件。 支持windows系统 下载后直接双击安装。 安装完成后,点开服务器软件 配置用户名 密码 根目录 然后启动服务。
Query Retrieve SCP Emulator
Sangfor SCP平台开放API接口,支持系统集成和二次开发。