Ubuntu下ssh服务的安装

前端之家收集整理的这篇文章主要介绍了Ubuntu下ssh服务的安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Ubuntu默认并没有安装ssh服务,如果通过ssh远程连接到Ubuntu,需要自己手动安装ssh-server。
判断是否安装ssh服务,可以通过如下命令进行:
ps -e|grep ssh
输出如下:
~$ ps -e|grep ssh
2151 ? 00:00:00 ssh-agent

5313 ? 00:00:00 sshd

ssh-agent表示ssh-client启动,sshd表示ssh-server启动了。

如果缺少sshd,说明ssh服务没有启动或者没有安装。
安装ssh-client命令:sudo apt-get install openssh-client

安装ssh-server命令:sudo apt-get install openssh-server

安装完成以后,先启动服务:sudo /etc/init.d/ssh start
启动后,可以通过“ps -e|grep ssh”查看是否正确启动。

ssh服务默认的端口是22,可以更改端口,使用如下命令打开ssh配置文件
sudo nano /etc/ssh/sshd_config

# Package generated configuration file   
# See the sshd(8) manpage for details   
# What ports,IPs and protocols we listen for  
Port 22
# Package generated configuration file
# See the sshd(8) manpage for details
# What ports,IPs and protocols we listen for
修改端口号(Port)后,重启ssh服务即可生效,命令如下:
sudo /etc/init.d/ssh restart


ssh服务启动后,即可登陆,登陆命令格式为:ssh 帐号@IP地址 -p
例如:ssh test@192.168.135.249 -p


可以通过SFTP工具进行登录

如:flashfxp 或者 FileZilla


配置ssh免密码登录

root@ubuntu:~/.ssh# ssh-keygen -t rsa  使用rsa加密
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
9e:32:c6:43:0c:37:92:29:be:cc:13:4a:23:c5:c4:5a root@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
| ..              |
| oE  o           |
| o+ = o          |
|.o . = .         |
|.oo   o S        |
|o+.o o . .       |
|. =   * o        |
|   . . +         |
|                 |
+-----------------+
root@ubuntu:~/.ssh# ls
id_rsa  id_rsa.pub  known_hosts    --id_rsa私钥  id_rsa.pub 公钥
root@ubuntu:~/.ssh# more id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpxApV3r+YQztiDcS2aK0eRLZjawAT9fSXNaTRYHkG
erVRdITYqBlJdYWSAyl8MQH4t5BxXTSt1iDl86fva87MWY5jKmoMPB/11uaB9SFC/Ir4Ym9mNmbIwsVf
WxD810iEEHJO4zfaZ1Nbm+ALwvFGnwXAasT6P1vp0XTCYdtleeBWfX9RubA8NUrNm3XXRaWXX2+lba1v
D4UZV1jrPWCf2TvAa0cMiiljIa8KX5mP9LQPxbskNzr1Q6cm3XrlAgGkIfUKR2VuJnajbC+wwuFP2r/i
QqQ62BcyzgsDO5C8obR8IXlGGHfpwPNNtVaG15WTx3Rq6869eRlZCm/hKVi3 root@ubuntu
root@ubuntu:~/.ssh# cp id_rsa.pub authorized_keys    (ssh启动需要读取 用户目录/.ssh 文件中的 authorized_keys)
root@ubuntu:~/.ssh# ls 
authorized_keys  id_rsa  id_rsa.pub  known_hosts


测试是否可以直接登录

root@ubuntu:~/.ssh# ssh localhost
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

New release '14.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Mon Feb 20 16:27:36 2017 from myhost01.local
root@ubuntu:~# exit
logout
Connection to localhost closed.
原文链接:https://www.f2er.com/ubuntu/354477.html

猜你在找的Ubuntu相关文章