Sunday, July 30, 2017

quickly log in remote sever

reference:
http://blog.csdn.net/leexide/article/details/17252369
https://my.oschina.net/aiguozhe/blog/33994

process:
local server:
1. ssh-keygen -t rsa (连续三次回车,即在本地生成了公钥和私钥,不设置密码)
2. ssh root@172.24.253.2 "mkdir .ssh;chmod 0700 .ssh" (需要输入密码, 注:必须将.ssh的权限设为700) (if remote server doesn't have ssh file)
3. scp ~/.ssh/id_rsa.pub root@172.24.253.2:.ssh/id_rsa.pub (需要输入密码)

remote server:
1. 
cat id_rsa.pub >> ~/.ssh/authorized_keys
2. 
 chmod 600 authorized_keys
3.
 chmod 700 -R ~/.ssh
注意都要在对应.ssh 文件目录下进行

Wednesday, July 19, 2017

python write to file buffer

https://stackoverflow.com/questions/18984092/python-2-7-write-to-file-instantly
https://stackoverflow.com/questions/3167494/how-often-does-python-flush-to-a-file
Use flush() or

For file operations, Python uses the operating system's default buffering unless you configure it do otherwise. You can specify a buffer size, unbuffered, or line buffered.
For example, the open function takes a buffer size argument.
"The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size. A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used."
bufsize = 0
f = open('file.txt', 'w', bufsize)
shareimprove this answer