1、客戶端保活:
options.client_alive_interval
options.client_alive_count_max
在wait_until_can_do_something()函數中實現
2、主進程監聽客戶端連接請求
main()
server_accept_loop()
3、接受客戶端連接請求后協商:
1)版本號協商:
main
sshd_exchange_identification
2)算法密鑰協商:
main
do_ssh2_kex
3)用戶名密碼驗證:
main
do_authentication2
input_service_request
input_service_request
authmethod_lookup
authmethod_lookup中遍歷全局變量 authmethods
authmethods->method_passwd
method_passwd->userauth_passwd
userauth_passwd
auth_password
sys_auth_passwd
4、驗證通過后shell啟動流程
main()
do_authenticated
do_authenticated2
server_loop2
debug1: server_init_dispatch
debug1: server_input_channel_open: ctype session rchan 0 win 131072 max 32768
debug1: input_session_request
debug1: channel 0: new [server-session]
debug1: session_new: session 0
debug1: session_open: channel 0
debug1: session_open: session 0: link with channel 0
debug1: server_input_channel_open: confirm session
debug1: server_input_channel_req: channel 0 request pty-req reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req pty-req
debug1: Allocating pty.
debug1: session_pty_req: session 0 alloc /dev/pts/4
debug1: server_input_channel_req: channel 0 request shell reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req shell
Starting session: shell on pts/4 for root from 10.1.5.200 port 54717 id 0
session_input_channel_req
session_shell_req
do_exec
do_exec_pty
do_child
execve()
5、啟動shell過程會寫入 /var/run/utmp文件(linux通過w或who命令查看登錄用戶就是讀取的該文件)
do_exec_pty
do_login
record_login
login_login
login_write
utm_write_entry
utmp_perform_logout
utmp_perform_login
utmp_write_library
pututline