๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TIL/Linux

1. ์ฃผํ”ผํ„ฐ ์„œ๋ฒ„ ๊ตฌ์ถ•ํ•˜๊ธฐ

๋ณดํ†ต ์ฃผํ”ผํ„ฐ๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์‹คํ–‰์‹œํ‚ค๋ฉด 127.0.0.1:8888 ๋กœ ์ ‘์†ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ด๋Š” ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์˜ ๊ธฐ๋ณธ ๊ฐ’์ด localhost๋กœ ์ ‘๊ทผํ•˜๋„๋ก ์„ค์ •๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋‚ด PC๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ PC๋กœ ๋ฐฉ๊ธˆ ๋งŒ๋“  ์ฃผํ”ผํ„ฐ ์„œ๋ฒ„์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ณ„๋„์˜ ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

1. jupyter_notebook_config.py ์ƒ์„ฑ ๋ฐ ์ˆ˜์ •


1) jupyter_notebook_config.py ํŒŒ์ผ ์ƒ์„ฑ

jupyter notebook --generate-config

 

์œ„์™€ ๊ฐ™์ด ์ ์œผ๋ฉด jupyter_notebook_config.py ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜๊ณ , ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ ๊ฒฝ๋กœ๋ฅผ ์•Œ๋ ค์ค๋‹ˆ๋‹ค. 

 

ex)home/azure/.jupyter/jupyter_config.py

2)jupyter_notebook_config.py ํŒŒ์ผ ์ˆ˜์ •

ipython ์ด๋ผ๊ณ  ์ž…๋ ฅํ•˜์—ฌ ์‰˜์Šคํฌ๋ฆฝํŠธ์— ์ง„์ž…ํ•˜๊ณ  ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

from notebook.auth import passwd 
passwd()

 

์œ„ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์›ํ•˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

์ž…๋ ฅํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ hash ์•”ํ˜ธํ™”ํ•˜์—ฌ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.

์ด ๋•Œ ์ถœ๋ ฅ๋œ hashed password๋ฅผ ๋ณต์‚ฌํ•ด๋‘ก๋‹ˆ๋‹ค.

 

์•„๋ž˜ ์ฝ”๋“œ๋กœ jupyter configํŒŒ์ผ์— ์ง„์ž…ํ•˜์—ฌ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

vi /home/azure/.jupyter/jupyter_config.py

 

c.NotebookApp.ip = '0.0.0.0'

c.NotebookApp.password = u'์œ„์—์„œ ๋ณต์‚ฌํ•œ hash password ์ž…๋ ฅ'

c.NotebookApp.open_browser = False

c.NotebookApp.port = ์›ํ•˜๋Š” ํฌํŠธ ์ž…๋ ฅ

c.NotebookApp.notebook_dir = ์ฃผํ”ผํ„ฐ ๊ธฐ๋ณธ ์›Œํ‚น ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ •

:/c.NotebookApp.ip ์ด๋Ÿฐ์‹์œผ๋กœ ์ฐพ์œผ๋ฉด ํ‚ค์›Œ๋“œ ๊ฒ€์ƒ‰์„ ํ†ตํ•ด ๋น ๋ฅด๊ฒŒ ์ฐพ์•„๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

1) c.NotebookApp.ip : 0.0.0.0 ํ˜น์€ ๋‚ด๋ถ€ ์•„์ดํ”ผ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

2) c.NotebookApp.password : ๋ณต์‚ฌํ•œ hash password๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

3) c.NotebookApp.open_browser = False : ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์—ด์ง€ ์•Š๋„๋ก False๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

4) c.NotebookApp.port : ์›ํ•˜๋Š” ํฌํŠธ ์ž…๋ ฅ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.(ํ•ด๋‹น ํฌํŠธ๊ฐ€ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ์—ด๋ ค์žˆ๋Š”์ง€ ํ™•์ธ ํ•„์š”, http๊นŒ์ง€๋งŒ ํ• ๊ฑฐ๋ฉด 8888๋กœ ์„ค์ •)

5) c.NotebookApp.notebook_dir : ์ฃผํ”ผํ„ฐ๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ์–ด๋–ค ๊ฒฝ๋กœ๊ฐ€ ๋ณด์ผ์ง€ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค (์ฃผํ”ผํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๊ฑด๋“œ๋ฆฌ๋ฉด ์•ˆ๋˜๋Š” ํŒŒ์ผ์ด ์žˆ๋‹ค๋ฉด ์•„์˜ˆ ๊ทธ๋Ÿฐ ํŒŒ์ผ๋“ค์ด ๋ณด์ด์ง€ ์•Š๋Š” ๊ฒฝ๋กœ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”)

 

๋‚ด๋ถ€ ์•„์ดํ”ผ์™€ ์™ธ๋ถ€ ์•„์ดํ”ผ ๊ด€๋ จํ•ด์„œ๋Š” ์•„๋ž˜ ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

inistory.tistory.com/79?category=881846

 

์™ธ๋ถ€ ์•„์ดํ”ผ ์ฃผ์†Œ / ๋‚ด๋ถ€ ์•„์ดํ”ผ ์ฃผ์†Œ ๊ฒ€์ƒ‰

์™ธ๋ถ€ ์•„์ดํ”ผ ์ฃผ์†Œ ํ™•์ธ curl ipinfo.io/ip ๋‚ด๋ถ€ ์•„์ดํ”ผ ์ฃผ์†Œ ํ™•์ธ sudo ifconfig inet ์˜†์— ์žˆ๋Š” ์ฃผ์†Œ๊ฐ€ ๋‚ด๋ถ€ ์•„์ดํ”ผ ์ฃผ์†Œ

inistory.tistory.com

 

2. SSL ์ธ์ฆ์„œ ์„ค์ • (http → https)


์œ„์—๊นŒ์ง€ ์™„๋ฃŒํ•˜๋ฉด http://(์™ธ๋ถ€์•„์ดํ”ผ์ฃผ์†Œ):(์›ํ•˜๋Š”ํฌํŠธ) ๋กœ ์ ‘์†์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋ณด์•ˆ์„ ๋” ๊ฐ•ํ™”ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” SSL ์ธ์ฆ์„œ ๋“ฑ๋ก์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

SSL ์ธ์ฆ์„œ๋Š” ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋กœ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์‚ฌ์ด์ž„์„ ์ฆ๋ช…ํ•ด์ฃผ๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค!

 

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

 

 

์œ„ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ธ์ฆ์„œ ๋“ฑ๋ก๊ณผ์ •์ด ๋‚˜์˜ค๊ณ  ๋ชจ๋‘ ์ˆ˜ํ–‰์„ ํ•˜๋ฉด,

ํ˜„ ๊ฒฝ๋กœ์— mycert.pem ๊ณผ mykey.key ํŒŒ์ผ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

๋‹ค์‹œ configํŒŒ์ผ์— ์ง„์ž…ํ•˜์—ฌ

#ํŒŒ์ผ ์ง„์ž…
sudo vi /home/azure/.jupyter/jupyter_notebook_config.py 
c.NotebookApp.certfile = u'/(์ธ์ฆ์„œ๊ฐ€ ์žˆ๋Š” ์ ˆ๋Œ€๊ฒฝ๋กœ)/mycert.pem'

c.NotebookApp.keyfile = u'/(์ธ์ฆ์„œ๊ฐ€ ์žˆ๋Š” ์ ˆ๋Œ€๊ฒฝ๋กœ)/mykey.key'
c.NotebookApp.ip = '*'

c.NotebookApp.password = u'sha1:bcd259ccf...<๋‚ด hashed password์ ์–ด์ฃผ๊ณ >'

c.NotebookApp.open_browser = False


c.NotebookApp.port = ์›ํ•˜๋Š” ํฌํŠธ ์ž…๋ ฅ
#์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ ์‹คํ–‰
jupyter-notebook

 

์ด์ œ https๋กœ ์ ‘๊ทผํ•˜์—ฌ ์ฃผํ”ผํ„ฐ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

https://(์™ธ๋ถ€ ์•„์ดํ”ผ ์ฃผ์†Œ):(์›ํ•˜๋Š” ํฌํŠธ)

 

ํ•˜์ง€๋งŒ ์œ„์˜ ์ƒํƒœ๋Š” ์„œ๋ฒ„์—์„œ ๋กœ๊ทธ์•„์›ƒ(exit)ํ•˜๋ฉด ์ฃผํ”ผํ„ฐ ์‹คํ–‰์ด ๋ฉˆ์ถฅ๋‹ˆ๋‹ค.

๊ณ„์†ํ•ด์„œ ์ฃผํ”ผํ„ฐ๋ฅผ ์ผœ๋†“๊ณ  ์‹ถ๋‹ค๋ฉด, ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ ์„œ๋ฒ„๋ฅผ ๋Œ์•„๊ฐ€๊ฒŒ ํ•ด์ฃผ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์ด์™€ ๊ด€๋ จํ•œ ํฌ์ŠคํŒ…์€ ์•„๋ž˜๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

inistory.tistory.com/78?category=881846

 

์ฃผํ”ผํ„ฐ ์„œ๋ฒ„ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ–‰ํ•˜๊ธฐ

ํ•˜์ง€๋งŒ ์œ„์˜ ์ƒํƒœ๋Š” ์„œ๋ฒ„์—์„œ ๋กœ๊ทธ์•„์›ƒ(exit)ํ•˜๋ฉด ์ฃผํ”ผํ„ฐ ์‹คํ–‰์ด ๋ฉˆ์ถฅ๋‹ˆ๋‹ค. ๊ณ„์†ํ•ด์„œ ์ฃผํ”ผํ„ฐ๋ฅผ ์ผœ๋†“๊ณ  ์‹ถ๋‹ค๋ฉด, ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ ์„œ๋ฒ„๋ฅผ ๋Œ์•„๊ฐ€๊ฒŒ ํ•ด์ฃผ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. 1) ๋ฐฑ๊ทธ๋ผ์šด๋“œ ๋“ฑ๋ก

inistory.tistory.com