分享

ssh重装ubuntu

 阳关旧友 2021-12-15

1、先停掉SSH服务:sudo stop ssh

2、卸载openssh-server:apt-get remove openssh-server

3、卸载openssh-client: apt-get remove openssh-server

4、安装openssh-server:apt-get install openssh-server

5、安装openssh-client:apt-get install openssh-client

6、安装完成以后,启动服务:sudo /etc/init.d/ssh start

7、启动后,查看服务是否正确启动: ps -e|grep ssh

8、确认ssh-server已经正常工作: netstat -tlp

2、生成密钥

ssh-keygen

中间过程会提示你存放密钥的地方Enter file in which to save the key (/home/gavin/.ssh/id_rsa):选择默认目录好了,直接回车;

然后会提示Enter passphrase (empty for no passphrase): 设置一个进入私钥的密码,在后边导入id_rsa 到puttygen会用到,随便设置一个好了(不过自己要记住);

上述过程执行完毕后会生成两个文件,一个是id_rsa(私钥),一个是id_rsa.pub(公钥);

这里将公钥改名为authorized_keys:

cd .ssh

mv id_rsa.pub authorized_keys

3、修改配置文件,/etc/ssh/sshd_config

sudo vi /etc/ssh/sshd_config

其中有这么一行# AuthorizedKeysFile  %h/.ssh/authorized_keys,把前面的#去掉即可;

ubuntu默认并没有安装ssh服务,如果通过ssh链接ubuntu,需要自己手动安装ssh-server。判断是否安装ssh服务,可以通过如下命令进行:

$ ssh localhost

ssh: connect to host localhost port 22: Connection refused

如上所示,表示没有还没有安装,可以通过apt安装,命令如下:

$ sudo apt-get install openssh-server

系统将自动进行安装,安装完成以后,先启动服务:

$ sudo /etc/init.d/ssh start

启动后,可以通过如下命令查看服务是否正确启动

$ ps -e|grep ssh

6212 ?        00:00:00 sshd

如上表示启动ok。注意,ssh默认的端口是22,可以更改端口,更改后先stop,

然后start就可以了。改配置在/etc/ssh/sshd_config下,如下所示。

$ vi /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

最后,应该是连接的时候了。请看如下命令:

启动、停止和重启SSH:

sudo /etc/init.d/ssh start

sudo /etc/init.d/ssh stop

sudo /etc/init.d/ssh restart

或者

sudo start ssh

sudo stop ssh

sudo restart ssh

卸载SSH

先停掉SSH服务:sudo stop ssh

然后:$ sudo apt-get –purge remove openssh-server

windows下如何使用ssh远程登录ubuntu

到windows平台将先前生成的私钥id_rsa,转换成putty所识别的格式(*.ppk),得到文件id_rsa.ppk.

(1)把linux上生成的id_rsa拷贝到windows平台下;

(2)下载puttygen.exe,(下载地址:http://www.chiark./~sgtatham/putty/download.html)然后打开,我们要让它帮我们做个通行证,生成id_rsa.ppk;

(3)选择“load”,载入以保存好的私钥文件:

a)弹出的对话框里把“文件类型”换成“所有文件”然后选中我们从ubuntu服务器上生成的id_rsa文件;

b)接着,它会提示你输入密码,这不是你linux用户密码,而是前面生成密钥时候的密码;

c)然后点击"save private key",注意(格式为*.ppk)因为putty只识别自己做的钥匙;

5、windows上启动putty,进行如下配置

(1)Session-Logging-Hostname:填上你的linux的ip

(2)Windows -Translation - 在下拉菜单里选上UTF-8,这里不设置,登录后将会出现中文乱码。

(3)Connection- Data - Auto login username:填上你登录ubuntu时用的用户名。

(4)Connection- SSH-Auth-Private key file for authentication:选上id_rsa.ppk;

然后点击open,按照提示输入密码即可访问。

转载至:

http://blog.csdn.net/swuteresa/article/details/9377169

http://blog.sina.com.cn/s/blog_7d892a6701016hmo.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多