微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/ubuntu/354477.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐