远程连接SSH

255 阅读1分钟

服务器安装SSH服务

安装SSH服务

yum install openssh-server

启动SSH

service sshd start
ps -ef | grep ssh

设置开机运行

chconfig sshd on

客户端安装SSH工具

  • xshell

客户端连接SSH服务

ssh username@ip

SSH config

  • config为了方便我们批量管理多个ssh
  • config存放在家目录 ~/.ssh/config
  • config配置语法
关键词语法 kv
Host 别名
HostName 主机名
Port 端口
User 用户名
IdentityFile 密钥文件的路径
  • 示例
host "imooc"
	HostName 192.168.x.xx
	User root
	Port 22
	IdentifyFile ~/.ssh/id_rsa.pub
	IdentitiesOnly yes

tip:虚拟机的IP会发生变化,用 ping 192.168.x.xx 判断是否能正常连接

ssh imooc //    就可以这样登陆了

SSH安全免密码登陆

  • ssh key 使用非对称加密方式生成公钥和私钥
  • 私钥存放在本地 ~/.ssh 目录
  • 公钥可以对外公开,放在服务器的 ~/.ssh/authorized_keys
  • Linux平台生成key
cd ~/.ssh
ssh-keygen -t rsa | ssh-keygen -t dsa

SSH安全端口

  • 修改SSH服务端口
  • 修改 /etc/ssh/sshd_config配置

service sshd restart