Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Create SSH Manager with Go
Search
syossan27
April 18, 2018
1.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Create SSH Manager with Go
This slide for Go(Un)Conference #1
https://gounconference.connpass.com/event/83112
syossan27
April 18, 2018
More Decks by syossan27
See All by syossan27
数値変えただけで年間約100万円コスト削減した話
syossan27
2
920
一人でちいさくはじめる Platform Engineering
syossan27
4
3.2k
一人SREが歩んだPlatform Engineeringスモールスタート実践録 ~ クラウドネイティブ会議版 ~
syossan27
4
2.3k
プロポーザル サポートガイドを読み解いていこう!
syossan27
3
1.1k
幻滅期を越える サイトリライアビリティ エンジニアリング
syossan27
1
280
一人SREが歩んだ Platform Engineering スモールスタート実践録
syossan27
2
2.1k
SREって何? 現場で学んだサイト信頼性の第一歩
syossan27
5
1.7k
知識0からカンファレンスやってみたらこうなった!
syossan27
5
810
突然のメモリ使用率上昇へ対応! k8sカスタムコントローラー開発事例
syossan27
2
600
Featured
See All Featured
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
510
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
980
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
630
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
560
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
560
Building Applications with DynamoDB
mza
96
7.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Transcript
$SFBUF44).BOBHFS XJUI(P Shota Inoue Go (Un) Conference #1
I’m Shota Inoue (@syossan27) Golang Beginner ʕ ◔ϖ◔ʔ <
Write simple code !
None
None
Create this
Why? ɾOn business ɾCreate SSH Client with Go is simple!
Feature ɾManage ssh connection informations ɾConnect using by connection information
ɾCrypt for connection information by AES key ɾBash completion
Search Github… Only this! But…
Implement ssh client Use this package. golang.org/x/crypto/ssh golang.org/x/crypto/ssh/terminal
1 client, err := ssh.Dial("tcp", "
[email protected]
") 2 session, err :=
client.NewSession() 3 fd := int(os.Stdin.Fd() 4 oldState, err := terminal.MakeRaw(fd)) 5 session.Stdout = os.Stdout 6 session.Stderr = os.Stderr 7 session.Stdin = os.Stdin 8 modes := ssh.TerminalModes{ 9 ssh.ECHO: 1, 10 ssh.TTY_OP_ISPEED: 14400, 11 ssh.TTY_OP_OSPEED: 14400, 12 } 13 err = session.RequestPty("xterm-256color", h, w, modes) 14 err = session.Shell() 15 err = session.Wait() Can implement by 15 line !
! Important processing 3 fd := int(os.Stdin.Fd() 4 oldState, err
:= terminal.MakeRaw(fd)) Important to exec ssh terminal in raw mode. If execute ssh terminal in cooked mode, buffering input. Therefore not work editor etc...
None
Manage connection informations 1. Input connection information 2. Crypt for
using by AES key (ex. ~/.ssh/id_rsa) 3. Write to file
Another way… Use boltdb for store connection informations. but…
Bash completion Put bash_completion file by manual operation is easily,
but it is not cool ! Therefore…
1 completionFileContent := ` 2 _cli_bash_autocomplete() { 3 local cur
opts base 4 COMPREPLY=() 5 cur="${COMP_WORDS[COMP_CWORD]}" 6 opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash- completion ) 7 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 8 return 0 9 } 10 complete -F _cli_bash_autocomplete en 11 ` 12 13 f, err := os.Create(completionFile) 14 _, err = f.Write([]byte(completionFileContent)) 15 16 loadConfigFileContent := "if [ -f '/etc/bash_completion.d/en' ]; then source '/etc/bash_completion.d/en'; fi” 17 18 f, err := os.OpenFile(“~/.bashrc”, os.O_APPEND|os.O_WRONLY, 0600) 19 fmt.Fprintln(f, loadConfigFileContent)
ʕ ◔ϖ◔ʔ < Go is God Fin.