blog/content/post/2013/10/25/2013-10-25-00001585.md

49 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: SSHでログインした際に任意のコマンドを実行する
author: kazu634
date: 2013-10-25
url: /2013/10/25/_1800/
geo_latitude:
- 38.305993
geo_longitude:
- 141.022698
geo_public:
- 1
wordtwit_posted_tweets:
- 'a:1:{i:0;i:1808;}'
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:1808;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- ssh
---
<time datetime="2013-10-25T20:03:00+09:00" pubdate data-updated="true">Oct 25<span>th</span>, 2013</time>
<div class="entry-content">
<p>
<a href="http://www.flickr.com/photos/gergtreble/4470265309/" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.flickr.com/photos/gergtreble/4470265309/', '');" title="Project 365 Day 87: Shaping Code by Greg McMullin, on Flickr"><img src="http://farm5.staticflickr.com/4020/4470265309_c1ef2663ed_z.jpg" width="640" height="426" alt="Project 365 Day 87: Shaping Code" /></a>
</p>
<p>
SSH経由でログインした場合に任意のコマンドを実行する方法を調査しました。どうやら <code>${HOME}/.ssh/rc</code> というファイルを作成し、そこに実行したいコマンドを記入すればいいようでした。
</p>
<blockquote>
<p>
If the file ~/.ssh/rc exists, sh(1) runs it after reading the environment files<br /> but before starting the user's shell or command.<br /> It must not produce any output on stdout; stderr must be used instead.
</p>
</blockquote>
<h2>
参考
</h2>
<ul>
<li>
<a href="http://kaworu.jpn.org/kaworu/2007-10-19-1.php" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://kaworu.jpn.org/kaworu/2007-10-19-1.php', 'sshでログインしたときにコマンドを実行する方法');">sshでログインしたときにコマンドを実行する方法</a>
</li>
<li>
<a href="http://enz0.net/linux/ssh_loginmail/" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://enz0.net/linux/ssh_loginmail/', '【だれだ】SSHでログインしたらメールで通知されるように仕込んでおこう');">【だれだ】SSHでログインしたらメールで通知されるように仕込んでおこう</a>
</li>
</ul>
</div>