Secure Shell(安全外壳协议,简称SSH)是一种加密的网络传输协议。SSH最常见的用途是远程登录系统,人们通常利用SSH来传输命令行界面和远程执行命令。使用频率最高的场合是类Unix系统,但是Windows操作系统也能有限度地使用SSH。2015年,微软宣布将在未来的操作系统中提供原生SSH协议支持,Windows 10 1809 版本已提供可手动安装的 OpenSSH工具。
测试平台: ubuntu14.04(root用户) - client ubuntu16.04(fh普通用户) - server
即ubuntu登录ubuntu,以后有机会和大家分享下Windows登录Ubuntu的操作。
1. SSH 分为 Client 和 Server
Ubuntu 默认自带SSH Client,端口号为22。如果没有,可通过sudo apt-get install openssh-client 来安装。如果作为Server端则需要安装SSH Server。
2. 安装SSH Server并启动
①查看SSH Server是否安装
dpkg -l|grep ssh
图中结果只安装了SSH Client
②安装 SSH Server
sudo apt-get install openssh-server
③查看是否安装成功&&查看是否启动成功
1> dpkg -l|grep ssh
图中结果说明SSH Server安装成功
2> ps -e|grep ssh
有sshd说明SSH Server已经启动成功
如果没有启动,可通过以下两种方式启动:
sudo /etc/init.d/ssh start
sudo service ssh start
3. SSH Server相关配置
SSH Server配置文件在 /etc/ssh/sshd_config,
①这里可以设置SSH Server 端口,默认是22,图中已修改为666
②允许root用户以任何认证方式登录
屏蔽PermitRootLogin without-password,增加PermitRootLogin yes
③重启SSH Server
sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start
4. Ubuntu root 登录SSH
①修改SSH Client 端口
配置文件在 /etc/ssh/ssh_config
Client 与 Server需ping的通
②终端登录命令:
ssh username@192.168.15.128
username为192.168.15.128的用户名称,192.168.15.128为SSH Server 的IP地址
登录时需输入username的root密码
ssh -p 1234 root@192.168.99.149
登录成功如图:在SSH Client使用ls查看当前文件列表
SSH Server 端使用ls命令结果对比:
③退出登录命令
exit
5. 新建文件测试
①SSH Client 使用touch 命令新建dh.txt文件
②SSH Server端效果图
6. SSH Client 使用 scp 命令获取 SSH Server端文件
①SSH Server 端新建dh6.txt,文件内容为hello world!
② SSH Client 获取文件
scp username@servername:/path/file /local_dir(本地目录)
往期精选文章: