顯示具有 sshlibrary 標籤的文章。 顯示所有文章
顯示具有 sshlibrary 標籤的文章。 顯示所有文章

2015年10月5日 星期一

git ssh id_rsa key

使用robot framework sshlibrary時,遇到錯誤訊息SSHException: No existing session原先以為是alise沒設好,後來發現是因為我的ssh id_rsa key有變動造成。

解決方法
使用root權限再跑一次即可

另外將ssh id_rsa.pub放到要連線的server~/.ssh/authorized_keys即可之後連線不需要輸入密碼(使用者名稱仍需要)

cp <path to id_rsa.pub> ~/.ssh/authorized_keys

如使用puttygen.exe,因為格式與openSSH不同,需在puttygen裡作轉換,並且public key的格式也需照框框內的內容貼上到authorized_keys,而非使用download public key的檔案。

另外也需要在ssh server上將權限設成可執行rwx------
chmod 700 ~/.ssh/authorized_keys
可用 ls -l 指令檢查
private key則需要600,不過一般都一定可以讀取所以不容易出錯

參考資料
自己
同事
authenticate agent
http://stackoverflow.com/questions/6832248/paramiko-no-existing-session-exception
authorized_keys
http://stackoverflow.com/questions/7260/how-do-i-setup-public-key-authentication
https://www.debian-administration.org/article/530/SSH_with_authentication_key_instead_of_password
puttygen.exe
http://blog.faq-book.com/?p=1444
chmod
http://unix.stackexchange.com/questions/36540/why-am-i-still-getting-a-password-prompt-with-ssh-with-public-key-authentication
ssh key on pi
https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
pfsense ssh key
https://doc.pfsense.org/index.php/HOWTO_enable_SSH_access

2015年2月3日 星期二

Robot Framework

Regular Expression
在使用 Read Until Regexp 時,卡在$及 . 很久,研究的結果是,由於使用或 ( | ) 所以要轉義兩次,第一次轉義後由於仍在 ( | ) 內所以仍被當成regular expression看,故要再轉義一次。

所以最後結果是 (\\$|\\.txt)

在使用SSHLibrary抓取terminal內字串時遇到換行符號,本來以為是\n,結果試了不是,又試了轉義以及\r都不是,最後靈機一動,居然是\r\n,記錄在這邊,希望能夠幫到人。

SSHLibrary Open Connection
與Telnet不同,ssh open connection 必須同時使用open connection及login兩個keyword,原因應該是因為ssh連接時是使用username@ip。robot因考慮Telnet使用同一組Keyword所以造成此限制。另外AttributeError: 'NoneType'錯誤則是因為沒有輸入帳號密碼,也就是上面所說沒有配合使用login造成。

unbalanced parenthesis則是括號沒有配合到,我遇到的狀況是空了兩格造成robot將右括號視作另一個argument了

SSHLibrary.Read until regexp 我有遇到狀況是會卡住,即使timeout時間到也不會FAIL。後來使用Read交叉測試的結果是因為output內有不同的編碼所以decode時卡住。Read結果的錯誤訊息為
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 318: invalid start byte
解決方法是close connection等到該段output被跳過之後再重新建立連線,換言之就是跳過該段output。另外也有一可能是整個編碼錯誤,如開始英文後轉為中文。此時可於open connection指定編碼encoding=

參考資料
自己測試結果
Read until regexp卡住
http://stackoverflow.com/questions/6180521/unicodedecodeerror-utf8-codec-cant-decode-bytes-in-position-3-6-invalid-dat
http://www.robotframework.net/question/68