harvey@harvey-Virtual-Machine:~$ ps -e |grep ssh 1670 ? 00:00:00 ssh-agent #用ps查看进程信息,如果只是显示这一条,说明系统只有SSH客户端没有服务器
harvey@harvey-Virtual-Machine:~$ sudo apt-get install openssh-server 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 将会安装下列额外的软件包:
harvey@harvey-Virtual-Machine:~$ ps -e|grep ssh 1670 ? 00:00:00 ssh-agent 3768 ? 00:00:00 sshd#有了sshd说明我的ssh服务安装和启动了
在介绍下面的知识之前先进性一个小的插曲--介绍一些service命令:
harvey@harvey-Virtual-Machine:~$ which service #查看service命令ide文件路径 /usr/sbin/service harvey@harvey-Virtual-Machine:~$ file /usr/sbin/service /usr/sbin/service: POSIX shell script, ASCII text executable #file命令发现service命令是一个shell脚本文件 #分析service的脚本发现此命令的作用是去/etc/init.d目录下寻找相应的服务,进性开始和关闭等操作。service使用的参数start可以换成restart表示重新启动,stop表示关闭,reload表示重新载入配置
#其实不是所有的linux发行版本中都有service命令,我们完全可以用/etc/init.d/ssh来启动或关闭服务。
#service开启ssh服务 harvey@harvey-Virtual-Machine:~$ sudo service ssh start ssh start/running, process 6505 harvey@harvey-Virtual-Machine:~$ ps -e|grep "ssh" 5217 ? 00:00:00 ssh-agent <defunct> 6505 ? 00:00:00 sshd #service关闭ssh服务 harvey@harvey-Virtual-Machine:~$ sudo service ssh stop ssh stop/waiting harvey@harvey-Virtual-Machine:~$ ps -e|grep "ssh" 5217 ? 00:00:00 ssh-agent <defunct> #ubunt下直接用/etc/init.d/
ssh的命令的提示是建议不要用直接的命令而是用service命令,因为ubuntu采用的是混合init的方式,所以直接用脚本可能不可用 harvey@harvey-Virtual-Machine:~$ sudo /etc/init.d/ssh stop [sudo] password for harvey: Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service ssh stop Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the stop(8) utility, e.g. stop ssh ssh stop/waiting
查找/etc下ssh相关的配置文件:
harvey@harvey-Virtual-Machine:~$ find /etc -name "ssh"#可以直接这样搜索因为首先配置文件肯定在/
etc文件夹下面,而是肯定是ssh开头这是规律 /etc/ssh /etc/init.d/ssh find: `/etc/cups/ssl‘: 权限不够 find: `/etc/ssl/private‘: 权限不够 /etc/bash_completion.d/ssh /etc/default/ssh
参考资料:linux service命令
Windows8 上用Ubuntu-Ubuntu启动SSH,布布扣,bubuko.com
原文:http://www.cnblogs.com/zhanghaiyublog/p/3616701.html