<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SPDLab &#187; ssh</title>
	<atom:link href="http://spdlab.net/tag/ssh/feed" rel="self" type="application/rss+xml" />
	<link>http://spdlab.net</link>
	<description></description>
	<lastBuildDate>Mon, 06 Sep 2010 10:31:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SSH &#8211; tips and tricks</title>
		<link>http://spdlab.net/ssh-tips-and-tricks</link>
		<comments>http://spdlab.net/ssh-tips-and-tricks#comments</comments>
		<pubDate>Thu, 25 Oct 2007 15:08:22 +0000</pubDate>
		<dc:creator>SPDLab</dc:creator>
				<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[forwarding]]></category>
		<category><![CDATA[socks proxy]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://78.46.87.37/~spdlab/?p=11</guid>
		<description><![CDATA[Many people tend to think of SSH as a secure substitution for insecure telnet remote administration. While basically that is it&#8217;s main purpose (SSH is short for secure shell) what you can do with this tool is definitely not limited by only one task&#8230; What will be explained here is mostly about open source implementation [...]]]></description>
			<content:encoded><![CDATA[<p>Many people tend to think of SSH as a secure substitution for  insecure telnet remote administration. While basically that is it&#8217;s main  purpose (SSH is short for secure shell) what you can do with this tool  is definitely not limited by only one task&#8230;<span id="more-11"></span></p>
<p>What will be explained here is mostly about open source  implementation of ssh &#8211; OpenSSH, so some things might be different if  you&#8217;re using something else.</p>
<p>Let&#8217;s first see about SSH security &#8211; is it really so secure? While  it&#8217;s hard to be exact on this issue one thing is certain &#8211; if you&#8217;re  using SSH protocol use only it&#8217;s version 2. SSH protocol version 1 is  known to have exploits for some time now and it is definitely not  advisable to use it. Sure, it&#8217;s not as bad as connecting with telnet,  but any reasonably well configured SSH server nowdays will offer you a  SSHv2 connection and even might be limited to this option only.</p>
<p>Some specific issues with SSH &#8211; if you&#8217;re new to it some things might  confuse you. For example &#8211; when logging in a system that you&#8217;ve never  logged in before it will prompt you for a authenticity check and display  you a key fingerprint.</p>
<p><span style="color: #808080;"><br />
The authenticity of host &#8216;somerandomserver.com (0.0.0.0)&#8217; can&#8217;t be  established.<br />
DSA key fingerprint is 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00.<br />
Are you sure you want to continue connecting (yes/no)?</span></p>
<p>Huh? What happens here &#8211; to prevent man-in-the-middle attacks you  must be sure that you are always communicating with the right system or  you might be sending passwords and other confidential information to  anyone who impersonates this system. IP addresses can be spoofed, DNS  entries are easily changed ARP poisoning can redirect your traffic and  so on&#8230; Once you&#8217;ve confirmed that this is exactly the system that you  want to login to its key will be memorized for later use and you wont  see it again &#8230;unless somebody tries to fool you &#8211; then you&#8217;ll get a  nice big warning about not matching the hosts keys. Needless to say, if  you are not absolutely sure that system you are logging to hasn&#8217;t  changed it&#8217;s keys stay away from further login!</p>
<p><span style="color: #808080;">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br />
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @<br />
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br />
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!<br />
Someone could be eavesdropping on you right now (man-in-the-middle  attack)!<br />
It is also possible that the DSA host key has just been changed.<br />
The fingerprint for the DSA key sent by the remote host is<br />
00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01.<br />
Please contact your system administrator.</span></p>
<p>So, what exactly is it that is possible to achieve with this tool, or  should I say toolbox?</p>
<h3>Remote logins</h3>
<p>Basic use of ssh client is<br />
<em> ssh hostname</em></p>
<p>Which will attempt login on host &#8220;hostname&#8221; on standard SSH port 22.  After successful login you can work normally as with console or telnet.<br />
Additional interesting basic options:<br />
-p : port to which you are connecting to (default 22)<br />
-l : login with different username then default (default is current  users username; this can be also accomplished as with username@host  syntax)<br />
-q and -v : first is for no messages at all (quiet) and second is for  verbose debugging messaging<br />
-t and -T : disabling and enabling pseudo-tty generation at servers end  (default enabled) &#8211; useful if you&#8217;re just making port forwarding<br />
-C : request compression of the transmission data (useful for slow  connections)<br />
-o : define a option value so values from configuration file can be  overridden<br />
-1 or -2 : try only version 1 or 2 of the protocol</p>
<h3>SFTP/SCP</h3>
<p>Secure alternatives for commonly used (unsecure) protocols &#8211; FTP and  rcp (remote copy)<br />
scp and sftp accept most of the normal ssh client&#8217;s options (attention:  port is here defined with -P unlike -p with ssh) but are used only for  file transfers. scp for single file transfer and sftp for multiple file  transfers.<br />
scp use:<br />
scp ~/somefile hostname:/tmp/somefile</p>
<p>This will copy &#8220;somefile&#8221; from your home directory to &#8220;/tmp/somefile&#8221;  on remote ssh server. If you ommit path on remote server files will be  copied to your home directory on server.<br />
Retrieval of files from remote server isn&#8217;t much harder either:<br />
scp hostname:/tmp/somefile ~/somefile_again</p>
<h3>Passwordless logins</h3>
<p>More appropriate for automated tasks but might help you if you tend  to forget passwords. Basically have a private/public key with which you  are authenticated on server. Of course, it&#8217;s more secure if you have  password also setup on your private key &#8211; otherwise anyone who steels  your private key can login into your servers. Yikes.<br />
By default when connecting your private keys will be searched within  ~/.ssh/ folder and are called id_dsa || id_rsa (depending on encryption  used), but private key file location can easily be defined with -i  option so you can use different keys for different servers:<br />
ssh -i ~/secretfiles/mykey_at_hostname hostname</p>
<p>Of course the same applies for scp and sftp&#8230;</p>
<h3>Remote command execution</h3>
<p>Who says you even need a terminal?<br />
ssh hostname df</p>
<p>If system command is added as parameter of the ssh connection command  (in this example it&#8217;s df) after successful login it will be executed  and logout happens as soon as it&#8217;s execution is finished. Useful for  checking on some services; or in this case &#8211; file system capacity  status.</p>
<h3>Port forwarding (poor man&#8217;s VPN)</h3>
<p>Forwarding a port thru remote system &#8211; weather you need it to secure  traffic over not so secure link or connect to the service which is  behind the firewall &#8211; this one is all time favorite ssh trick<br />
So, presumably you need to check on some webpage which is available only  inside LAN of your network from internet and you have only ssh access  to server there. Imposible? Not with ssh:<br />
ssh -L 8080:webserver:80 hostname<br />
where 8080 is port on your client ssh computer, webserver is LAN address  of the webserver in LAN and 80 is webservers http port</p>
<p>Now type in http://localhost:8080 in your browser and work like  you&#8217;re there&#8230; As you can see -L is a very powerful option and it does  forwards one port from some host (ports for localhost and remote hosts  port can be set up as needed) to your local computer.<br />
Additional use of this is anonymous surfing (or some other form of  activity) &#8211; ports can be forwarded from whichever hosts your ssh server  has connectivity to and port forwarding has a very interesting feature:  all traffic made to that remote host seems like it originates only from  ssh server and without any trace of your local computers address.</p>
<h3>Reverse (remote) port forwarding</h3>
<p>Forwarding a port on a local system to be available on remote system<br />
Similar to port forwarding, but of reverse nature like it&#8217;s name says &#8211;  expose your local network hosts to anybody who has access to remote  servers forwarded port. Use with caution &#8211; you never know who&#8217;s  listening on the other end&#8230;<br />
ssh -R 8080:webserver:80 hostname<br />
where 8080 is port on remote ssh server, webserver is LAN address of the  webserver in LAN and 80 is webservers http port</p>
<p>Anyone who can access remote ssh servers 8080 port can now browse  webserver in your LAN (do you really want this?). Also, with this your  computer works as anonymous proxy for chosen webserver (or any other  protocol depending on ports used).</p>
<h3>SOCKS Proxy</h3>
<p>Believe it or not, SSH can serve as SOCKS proxy<br />
ssh -D 12345 hostname<br />
where 12345 is port on your local computer</p>
<p>Huh? Is it this easy? Yep &#8211; dynamic port forwarding as it is usually  called does just this &#8211; makes a SOCKS v4/5 out of your computer and all  you need to do is point your SOCKS-aware applications to the chosen  port&#8230;</p>
<h3>Punching holes in HTTPS proxy</h3>
<p>OK, now this isn&#8217;t exactly a ssh-only feature (proxytunnel does most  of the work here) but might be the only way to make your way thru the  corporate restrictive web policies</p>
]]></content:encoded>
			<wfw:commentRss>http://spdlab.net/ssh-tips-and-tricks/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

