文章目录
1.【必要性】
两台电脑间通过SSH配置,建立客户端和服务器端的通信,应用的场合。
1)嵌入式板子(LINUX)上做开发时,没有屏幕或者屏幕太小,不便调试;
2)做DL的经常需要在一台电脑(本地主机)上写代码,另一台电脑(服务器,计算力强)上进行训练为了在local主机下也可以随时跑程序,调代码,同时省流量而且迅速;
2.【ssh命令连接步骤】
step1:SSH程序的安装
确保在服务器上安装好了openssh-server程序,在本地主机上安装好了openssh-client程序。
sudo apt install openssh-client #本地主机运行此条,实际上通常是默认安装client端程序的
sudo apt install openssh-server #服务器运行此条命令安装
step2:服务器启动ssh服务
以下命令都只针对服务器端(server only)。
一般服务器上安装ssh完成后,会自动启动ssh服务,并且默认随系统启动,如果没有,请手动启动:
sudo /etc/init.d/ssh start #服务器启动ssh-server服务
停止或重启命令:
sudo /etc/init.d/ssh stop #server停止ssh服务
sudo /etc/init.d/ssh restart #server重启ssh服务
#####注意:
为了保证嵌入式板子每次开机都可以自启动ssh,需要进行如下配置:
sudo vi /etc/rc.local
在exit 0语句前加入: /etc/init.d/ssh start ,然后:wq保存并退出即可。
step3:查询服务器的ip地址
在服务器终端运行以下命令:
ifconfig
在返回信息中找到自己的ip地址, 从我的返回信息中看到,我的ip地址(inet地址)是:192.168.1.114。
step4:在本地主机端ssh远程登录服务器
这一步需要知道服务器的用户名(我的服务器名字是egg)及IP地址。
在本地主机上运行以下命令:
egg@192.168.1.114
#或
ssh -l egg 192.168.1.114
如果需要调用图形界面程序
ssh -X egg@192.168.1.114
注意:
若服务器的SSH服务没有开启在22端口,那么SSH链接时则需要用-p指定端口,若端口号指定为50,则:
ssh -p 50 egg@192.168.1.114
step5:退出远程登录
用Ctrl+D或者
exit
3.报错及解决办法(删除原有known_hosts):
报错1:若在ssh连接时,出现如下报错:
问题描述
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
ea:24:31:8d:03:07:36:db:2f:74:15:5d:58:67:a3:5b.
Please contact your system administrator.
Add correct host key in /var/root/.ssh/known_hosts to get rid of this message.
Offending key in /var/root/.ssh/known_hosts:1
RSA host key for 192.168.1.114 has changed and you have requested strict checking.
Host key verification failed.
解决办法
则,删除原有known_hosts,方法为:
ssh-keygen -R 192.168.1.114 # 要连接的服务器端的ip地址
报错2:Permission denied, please try again.
问题描述
$ ssh root@192.168.1.114
root@192.168.1.114's password:
Permission denied, please try again.
解决办法
修改要访问的服务器中的sshd_config配置文件,方法为:
- 打开该配置文件:
vim /etc/ssh/sshd_config
- 然后做如下更改:
将 PermitRootLogin without-password 改为 PermitRootLogin yes - 最后重启 SSH:
sudo service ssh restart