Linux环境下安装ssh

前言

在配置 Hadoop 集群分布时,要使用 SSH 免密码登陆,spark 也是。此处只简单介绍 ssh 的安装,后续的免密码登陆在 Spark 配置文章中详细介绍、记录。html

简单介绍

维基百科定义:web

Secure Shell(缩写为 SSH),由 IETF 的网络工做小组(Network Working Group)所制定;SSH 为一项建立在应用层和传输层基础上的安全协议,为计算机上的 Shell(壳层)提供安全的传输和使用环境。ubuntu

SSH 是目前较可靠,专为远程登陆会话和其余网络服务提供安全性的协议。
SSH 有不少功能,它既能够代替 Telnet,又能够为 FTP、POP、甚至为 PPP 提供一个安全的 “通道”。安全

SSH 分为客户端和服务端。
服务端是一个守护进程,通常是 sshd 进程,在后台运行并响应来自客户端的请求。提供了对远程请求的处理,通常包括公共密钥认证、密钥交换、对称密钥加密和非安全链接。
客户端通常是 ssh 进程,另外还包含 scp、slogin、sftp 等其余进程。ruby

SSH 安装及配置

SSH 分客户端 openssh-client 和 openssh-server
好像是 Ubuntu 等 Linux 系统已经有了 openssh-server 服务,所以只须要安装 ssh 服务便可。服务器

安装 ssh

按照王家林 spark 书本介绍,使用下面的命令:markdown

 
 
 
 
  • 1
# apt-get install ssh

这里是管理员帐号,所以不须要使用sudo提高权限。普通用户注意在前面加上sodo网络

或者使用下面的命令:app

 
 
 
 
  • 1
# apt-get install openssh-client

启动服务

管理员权限下:ssh

 
 
 
 
  • 1
  • 2
  • 3
# /etc/init.d/ssh stop //中止 # /etc/init.d/ssh start //启动 # /etc/init.d/ssh restart //重启

OR

 
 
 
 
  • 1
  • 2
  • 3
# service ssh start # service ssh stop # service ssh restart

若是有警告提示的话,能够尝试第二种 service 方式。警告提示:

 
 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
root@Tbox:~/.ssh# /etc/init.d/ssh start Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service ssh start Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the start(8) utility, e.g. start ssh ssh start/running, process 3717

即:

 
 
 
 
  • 1
root@Tbox:~# service ssh start

此时则不会出现刚才的提示。

验证是否安装成功

成功的提示以下:

 
 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
root@Tbox:~/.ssh# ssh localhost root@localhost's password: Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic x86_64) * Documentation: https://help.ubuntu.com/ 298 packages can be updated. 251 updates are security updates. New release '14.04.4 LTS' available. Run 'do-release-upgrade' to upgrade to it. Your Hardware Enablement Stack (HWE) is supported until April 2017. Last login: Wed Jun 29 13:55:07 2016 from localhost root@Tbox:~#

以后继续进行的全部的操做都是经过 ssh 登陆本机进行的。

查看服务

能够经过命令:

 
 
 
 
  • 1
# ps -e|grep ssh

查看 ssh 相关服务有没有开启,或者针对性的关闭多余服务(#kill -9 3717)

其实上面第一种方式操做开启 ssh 服务的时候,服务已经启动起来了:

 
 
 
 
  • 1
  • 2
  • 3
  • 4
root@Tbox:~/.ssh# ps -e|grep ssh 2660 ? 00:00:00 ssh-agent 3717 ? 00:00:00 sshd

退出 ssh

直接在终端中输入 exit 便可

演示以下:

 
 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
root@Tbox:~# ps -e|grep ssh 2660 ? 00:00:00 ssh-agent 3745 ? 00:00:00 sshd 3748 pts/0 00:00:00 ssh 3749 ? 00:00:00 sshd root@Tbox:~# exit logout Connection to localhost closed. root@Tbox:~/.ssh# ps -e|grep ssh 2660 ? 00:00:00 ssh-agent 3745 ? 00:00:00 sshd root@Tbox:~/.ssh#

配置

修改 / etc/ssh/sshd_config 文件进行参数配置,具体配置根据须要查询资料便可。

以后能够配置公钥私钥,使服务器相互访问。

更多地资料能够查看官方文档,或者参考相关博客。

本文参考文章:
http://www.cnblogs.com/rond/p/3688529.html
http://www.cnblogs.com/xiazh/archive/2010/08/13/1798844.html
http://jingyan.baidu.com/article/9c69d48fb9fd7b13c8024e6b.html