Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- bash
- port
- Eclipse
- Source
- 단축키
- vscode
- resource
- import
- web.xml
- profile
- netsh
- Mac
- 네트워크
- plugin
- GIT
- grep
- find
- Windows 10
- tomcat
- context
- VirtualBox
- Windows
- xargs
- lsof
- ssh
- IntelliJ
- 줄바꿈 문자
- maVen
- JavaScript
- Quartz
Archives
- Today
- Total
develog
[bash] ssh "bash -s" sudo 실행시 오류 본문
aa.sh 파일 내용
#!/bin/bash
sudo hostname
ssh 를 "bash -s" 로 실행시 sudo 명령어가 있는 경우 오류가 발생한다
# script 파일 안에 sudo 명령이 있거나
ssh user@server "bash -s" < aa.sh
# heredoc 사용시 sudo 명령이 있으면
ssh user@server "bash -s" << EOF
sudo hostname
EOF
# 아래 오류 메시지가 나온다
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
echo "password" | ssh -t "sudo -S bash -s" 를 사용한다
# 로컬 script 파일을 실행
echo "password" | ssh -t user@server "sudo -S bash -s" < aa.sh
# heredoc 으로 실행
echo "password" | ssh -t user@server "sudo -S bash -s" << EOF
sudo hostname
EOF
sudo --help 내용
Options:
-A, --askpass use a helper program for password prompting
-p, --prompt=prompt use the specified password prompt
-S, --stdin read password from standard input
$ sudo --help
sudo - execute a command as another user
usage: sudo -h | -K | -k | -V
usage: sudo -v [-ABkNnS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-ABkNnS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command [arg ...]]
usage: sudo [-ABbEHkNnPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i | -s] [command [arg ...]]
usage: sudo -e [-ABkNnS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...
Options:
-A, --askpass use a helper program for password prompting
-b, --background run command in the background
-B, --bell ring bell when prompting
-C, --close-from=num close all file descriptors >= num
-D, --chdir=directory change the working directory before running command
-E, --preserve-env preserve user environment when running command
--preserve-env=list preserve specific environment variables
-e, --edit edit files instead of running a command
-g, --group=group run command as the specified group name or ID
-H, --set-home set HOME variable to target user's home dir
-h, --help display help message and exit
-h, --host=host run command on host (if supported by plugin)
-i, --login run login shell as the target user; a command may also be specified
-K, --remove-timestamp remove timestamp file completely
-k, --reset-timestamp invalidate timestamp file
-l, --list list user's privileges or check a specific command; use twice for longer format
-n, --non-interactive non-interactive mode, no prompts are used
-P, --preserve-groups preserve group vector instead of setting to target's
-p, --prompt=prompt use the specified password prompt
-R, --chroot=directory change the root directory before running command
-S, --stdin read password from standard input
-s, --shell run shell as the target user; a command may also be specified
-T, --command-timeout=timeout terminate command after the specified time limit
-U, --other-user=user in list mode, display privileges for user
-u, --user=user run command (or edit file) as specified user name or ID
-V, --version display version information and exit
-v, --validate update user's timestamp without running a command
-- stop processing command line arguments
Comments