SSH服务器 - 获取sshd进程转发端口#N的pid

时间:2017-05-15 21:21:55

标签: linux ssh server pid ssh-tunnel

我正在运行一个服务器(Ubuntu Server 14.04),它允许客户端从他们的设备(Raspberry Pi)创建一个ssh隧道,这样他们就可以从互联网访问他们的Web服务器(作为遍历NAT的方法)。我可以使用ps -u username获取用户拥有的进程列表(对于所有设备都是相同的)(此用户仅运行sshd转发端口),但我无法通过端口过滤这些进程'转发。所以问题是,如何获得转发端口#N的sshd的pid?

1 个答案:

答案 0 :(得分:2)

您可以使用 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let identifier = "Education" if annotation is Education { var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) if annotationView == nil { annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) annotationView!.canShowCallout = true let btn = UIButton(type: .detailDisclosure) annotationView!.rightCalloutAccessoryView = btn } else { annotationView!.annotation = annotation } return annotationView } return nil } 命令,因为所有内容都是linux上的文件。

lsof这样的东西可以满足你的要求。当我在我的机器上为端口80运行时,它有这样的输出:

lsof -Pan -i | grep :PORT

Command PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 1104 root 6u IPv4 23348 0t0 TCP *:80 (LISTEN) nginx 1105 www-data 6u IPv4 23348 0t0 TCP *:80 (LISTEN) nginx 1106 www-data 6u IPv4 23348 0t0 TCP *:80 (LISTEN) nginx 1107 www-data 6u IPv4 23348 0t0 TCP *:80 (LISTEN) nginx 1108 www-data 6u IPv4 23348 0t0 TCP *:80 (LISTEN) 的更多内容here