-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcygwin.html
214 lines (164 loc) · 7.73 KB
/
cygwin.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html>
<head>
<title>Dan's Level 2 - Cygwin page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://www.holbertonschool.com/level2/holberton.css" rel="stylesheet">
<link href="styles.css" rel="stylesheet">
<script src="behavior.js"></script>
</head>
<body class="works_on_smartphone">
<header>
<div class="right">
<ul>
<li class="logo">☎</li>
<li><a href="index.html">Index</a></li>
<li><a href="tweets.html">Tweets</a></li>
<li><a href="cygwin.html">Cygwin</a></li>
</ul>
</div>
</header>
<main>
<article>
<h1>Toot toot toroot toot: SSH on my windows PC at home!</h1>
<p>Cygwin is a linux emulator for Windows that works as an SSH
server (with the OpenSSH package) and can serve other
operating systems. Now that I am in San Francisco, I can
access my computer desktop in New York from the command
line... just like the server on this website! I have spent
probably too much time configuring and playing around with
it, but that only means I have learned a few things to
fill this page with :)</p>
<h2>Aliases</h2>
<p>After installing <a href="http://www.cygwin.com">cygwin</a> and
openSSH, I was able to remotely connect to my computer at
home. But one thing that I realized is that I cannot
remember the IP address of my computer at home every time I
want to log in.</p>
<p>This is where aliases come into play. I discovered that I
can have aliases for frequent commands both on my local
MacBook laptop as well as on the remote machine.</p>
<h3>On my local MacBook</h3>
<p>On my MacBook Air with OS X El Capitan 10.11, I modified my
'.bash_profile' file. The file can be accessed with Emacs with
the following command:</p>
<pre>emacs ~/.bash_profile</pre>
<h3>On my remote Windows 7</h3>
<p>For some reason, what worked above did not work remotely on
Cygwin. I figured out that you have to modify a different
file, and everything works after that :) I edited a file
called '.bashrc' using Emacs. The command to do this is as
follows:</p>
<pre>emacs ~/.bashrc</pre>
<h3>My bash aliases</h3>
<p>This is what my bash file looks like. I can now log into
the holberton server and to my home server without having to
look up the IP addresses on my machines!</p>
<img alt="screenshot showing example commands." src="bashfile.png">
<p>After saving the changes and closing and re-opening my
terminal windows, I can simply type "holberton" into the
terminal and I will be taken straight onto my Holberton Level
2 website. :)</p>
<h3>SSH keys, to avoid remembering the password!</h3>
<p>Unfortunately, we cannot change the root password on this
challenge, and the password is impossible to remember! I
have to copy and paste the password every time I log in
to the Holberton server. There is way to avoid the
password altogether using SSH keys!</p>
<p><del>I got an SSH key I generated to work with my computer at
home, but I spent way too much time doing this and so I
am pressed for time to finish the challenge and won't be
able to explain it at this point.</del></p>
<p><b>The Secure SHell (SSH) can work with different encryption
types. The one we will use is RSA.</b></p>
<h2>How SSH-RSA encrypted keys work to authenticate you</h2>
<p>There are two keys. One that encodes (public key), and one
that decodes (private key). The public key is not capable of
decoding, and it can be generated from the private key. Think
of the private key as a "master" key. It is able
to <i>lock</i> and <i>unlock</i>. The public key can
only <i>lock</i>.</p>
<p>If you don't have these, don't worry, that just means you
need to generate them. The folllowing section shows you
how.</p>
<h2>Generating keys</h2>
<p>First, we create a private key. Then, we generate a public
key from the private key. The following command will do
both.</p>
<pre>ssh-keygen -t rsa</pre>
<!-- <p></p> !-->
<p>At each prompt, just leave blank and press Enter. Now you
have your pair of private and public keys!</p>
<h2>Using your keys with your server</h2>
<p>Now that you have generated your keys, you can put them to use.</p>
<p>Your private key can be found in the local ~/.ssh/
directory. cd into it, and run ls. Your private key will be
called id_rsa. Your public key is there as well, called
id_rsa.pub.</p>
<p>Open up another terminal (let's call it terminal 2), and
log in to your remote server. Personally, I will log in to my
remote Windows PC with Cygwin installed, but these commands
work on Linux as well.</p>
<p>First, on terminal 2, cd into the remote server's ~/.ssh
directory. If it doesn't exist, use mkdir to make it. In this
directory, we will create a file called 'authorized_keys'. To
do this, run the following command:</p>
<pre>emacs authorized_keys</pre><p></p>
<p>This is where your public key will go (follow the steps
below). Remember, this will allow you to log in to your remote
server without a password, so make sure no one has stealthily
installed another key in there (make sure the file is
blank). Keep emacs open.</p>
<p>On terminal 1, cd into your local ~/.ssh directory. Run
emacs, copy the contents of the public key file (id_rsa.pub)
onto the file in terminal 2, and save it. Yes, good ol' copy
and paste. :)</p>
<p>You are done. You can now log into your server without a
password!</p>
<h2>Post Scriptum</h2>
<p>You might be wondering what would happen if you had a
private key already but you either lost your public key or
never had it in the first place. Turns out you can generate a
private key from a public key by specifying the -y option on
ssh-keygen. Run 'man ssh-keygen' for information on how to do
this.</p>
<h3>Resources</h3>
<pre>http://www.w3schools.com/tags/tag_pre.asp</pre>
<pre>http://getgrav.org/blog/mac-os-x-apache-setup-multiple-php-versions</pre>
<pre>https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2</pre>
<pre>http://askubuntu.com/questions/53553/how-do-i-retrieve-the-public-key-from-a-ssh-private-key</pre>
<pre>http://curiositalabs.com/2013/03/how-to-style-your-code-snippets/</pre>
<pre>http://www.w3schools.com/cssref/css_units.asp</pre>
<h3>Back to the <a href="index.html">index</a>.</h3>
</article>
<aside><div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
*/
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//danlevel2.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript></aside>
</main>
<footer>
<p>Made by <a href="https://twitter.com/dalzuga"
target="_blank">Daniel Alzugaray</a>
for <a href="https://www.holbertonschool.com"
target="_blank">Holberton School</a></p>
</footer>
<script id="dsq-count-scr" src="//danlevel2.disqus.com/count.js" async></script>
</body>
</html>