查看当前 Ubuntu 是否安装了 ssh-server 服务. 默认系统只安装了 ssh-client 服务.
使用 dpkg -l | grep ssh
$ dpkg -l | grep ssh ii libssh-4:amd64 0.8.0~20170825.94fa1e38-1ubuntu0.2 amd64 tiny C SSH library (OpenSSL flavor) ii libssh-gcrypt-4:amd64 0.8.0~20170825.94fa1e38-1ubuntu0.2 amd64 tiny C SSH library (gcrypt flavor) ii openssh-client 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines
安装 ssh-server 服务
sudo apt-get install openssh-server
查看安装情况
$ dpkg -l | grep ssh ii libssh-4:amd64 0.8.0~20170825.94fa1e38-1ubuntu0.2 amd64 tiny C SSH library (OpenSSL flavor) ii libssh-gcrypt-4:amd64 0.8.0~20170825.94fa1e38-1ubuntu0.2 amd64 tiny C SSH library (gcrypt flavor) ii openssh-client 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines ii openssh-server 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) server, for secure access from remote machines ii openssh-sftp-server 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) sftp server module, for SFTP access from remote machines ii ssh-import-id 5.7-0ubuntu1.1 all securely retrieve an SSH public key and install it locally
查看启动状态, 使用 ps -e | grep ssh
$ ps -e | grep ssh 2081 ? 00:00:00 ssh-agent 25213 ? 00:00:00 ssh-agent 25514 ? 00:00:00 sshd
可以看到 sshd
服务已经启动.
如果没有则可以这样启动 sudo /etc/init.d/ssh start
或 sudo service ssh start
配置
ssh-server 配置文件位于 /etc/ssh/sshd_config,在这里可以定义 SSH 的服务端口,默认端口是22,可以自定义成其他端口,如222。
然后重启SSH服务: sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start
登录远程服务器
ssh username@ip