LoginSignup
25
27

More than 5 years have passed since last update.

WinSCPでsudoを使う(SakuraVPS)

Last updated at Posted at 2014-04-28

SakuraVPS(CentOS 6.5) WinSCPでsudoを使えるようにする。

Sudoersを編集する

ここを参考にした。
http://winscp.net/eng/docs/faq_su

※WinSCPで使うログインユーザーはusernameと仮定。

$ sudo visudo
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
username  ALL=(ALL)       ALL
username  ALL=NOPASSWD: /usr/libexec/openssh/sftp-server

補足

sudo使用時にパスワードを要求される状態では、WinSCPは使えなさそうなので、パスワードなしで使えるようにする。

username ALL=NOPASSWD: /usr/libexec/openssh/sftp-serverとして、SFTPセッションの時のみパスワードなしでsudoを使えるようにする。

※もちろんusername ALL=NOPASSWD: ALLとすればセキュリティレベルは下がるが、便利にはなる。

WinSCPの設定

接続情報を入力する場所の設定を開き、SFTP>SFTPサーバにsudo /usr/libexec/openssh/sftp-serverを設定する。

恐らくこれだけでは接続できない。

winscp.png

Sudoersをもう一度編集

次は以下を設定

$ sudo visudo
#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
#         You have to run "ssh -t hostname sudo <cmd>".
#
Defaults    requiretty

↓ 変更後

Defaults    requiretty
Defaults:username !requiretty

ヒント
Is it okay to disable requiretty?
http://unix.stackexchange.com/questions/65774/is-it-okay-to-disable-requiretty

接続する

これでrootユーザーでなくてもOK!

とはいえ操作ミスで大事なファイルを消したくはないので、通常(sudoしない用)の設定を作り直して、使うようにしてみます。

winscp2.png

定石ってやつを知らないが、こんな感じでよさそうですね。

25
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
27