ubuntu怎么修改ssh root密码
答案:2 悬赏:20
解决时间 2021-03-12 20:34
- 提问者网友:曖昧情执
- 2021-03-12 09:10
ubuntu怎么修改ssh root密码
最佳答案
- 二级知识专家网友:一起来看看吧
- 2021-03-12 09:19
在使用虚拟机过程中,因为时常要切换到win7下调试,所以比较麻烦。所以最近尝试在win下用SSH Secure Shell Client登陆虚拟机,为了避免反复的su切换到root,所以希望以root用户登陆。 1.首先win7安装SSH Secure Shell Client,Ubuntu下也使用apt...
全部回答
- 1楼网友:萌萌哒小可爱
- 2021-03-12 10:38
设置root密码
1
使用原密钥登陆远程主机,默认登陆用户为ubuntu
得到远程机ip
如果是aws,在ec2控制台查看一下实例的公有 ip,复制一下
cmd
ssh -i 密钥 [email protected]
2
空密码不让登陆的,所以要给root一个新密码
su
passwd root
输入两次新密码就可以了
end
修改/etc/ssh/sshd_config
修改
vi /etc/ssh/sshd_config
密码登陆
permitrootlogin yes
strictmodes no
permitemptypasswords yes
passwordauthentication yes
密钥登陆
hostkey /etc/ssh/ssh_host_rsa_key
hostkey /etc/ssh/ssh_host_rsa1_key
hostkey /etc/ssh/ssh_host_dsa_key
hostkey /etc/ssh/ssh_host_ecdsa_key
hostkey /etc/ssh/ssh_host_ed25519_key
rsaauthentication yes
pubkeyauthentication yes
authorizedkeysfile %h/.ssh/authorized_keys
如果不想一个个改,也可以复制粘贴
全文如下
#/etc/ssh/sshd_config
# package generated configuration file
# see the sshd_config(5) manpage for details
# what ports, ips and protocols we listen for
port 22
# use these options to restrict which interfaces/protocols sshd will bind to
#listenaddress ::
#listenaddress 0.0.0.0
protocol 2
# hostkeys for protocol version 2
hostkey /etc/ssh/ssh_host_rsa_key
hostkey /etc/ssh/ssh_host_rsa1_key
hostkey /etc/ssh/ssh_host_dsa_key
hostkey /etc/ssh/ssh_host_ecdsa_key
hostkey /etc/ssh/ssh_host_ed25519_key
#privilege separation is turned on for security
useprivilegeseparation yes
# lifetime and size of ephemeral version 1 server key
keyregenerationinterval 3600
serverkeybits 1024
# logging
syslogfacility auth
loglevel info
# authentication:
logingracetime 120
permitrootlogin yes
strictmodes no
rsaauthentication yes
pubkeyauthentication yes
authorizedkeysfile %h/.ssh/authorized_keys
# don't read the user's ~/.rhosts and ~/.shosts files
ignorerhosts yes
# for this to work you will also need host keys in /etc/ssh_known_hosts
rhostsrsaauthentication no
# similar for protocol version 2
hostbasedauthentication no
# uncomment if you don't trust ~/.ssh/known_hosts for rhostsrsaauthentication
#ignoreuserknownhosts yes
# to enable empty passwords, change to yes (not recommended)
permitemptypasswords yes
# change to yes to enable challenge-response passwords (beware issues with
# some pam modules and threads)
challengeresponseauthentication no
# change to no to disable tunnelled clear text passwords
passwordauthentication yes
# kerberos options
#kerberosauthentication no
#kerberosgetafstoken no
#kerberosorlocalpasswd yes
#kerberosticketcleanup yes
# gssapi options
#gssapiauthentication no
#gssapicleanupcredentials yes
x11forwarding yes
x11displayoffset 10
printmotd no
printlastlog yes
tcpkeepalive yes
#uselogin no
#maxstartups 10:30:60
#banner /etc/issue.net
# allow client to pass locale environment variables
acceptenv lang lc_*
subsystem sftp /usr/lib/openssh/sftp-server
# set this to 'yes' to enable pam authentication, account processing,
# and session processing. if this is enabled, pam authentication will
# be allowed through the challengeresponseauthentication and
# passwordauthentication. depending on your pam configuration,
# pam authentication via challengeresponseauthentication may bypass
# the setting of "permitrootlogin without-password".
# if you just want the pam account and session checks to run without
# pam authentication, then enable this but set passwordauthentication
# and challengeresponseauthentication to 'no'.
usepam yes
生成私钥
ssh-keygen -t dsa /etc/ssh/ssh_host_dsa_key
ssh-keygen -t ecdsa /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 /etc/ssh/ssh_host_ed25519_key
ssh-keygen -t rsa /etc/ssh/ssh_host_rsa_key
ssh-keygen -t rsa1 /etc/ssh/ssh_host_rsa1_key
chmod 600 /etc/ssh/*key
复制公钥到authorized_keys
cat /etc/ssh/ssh*pub>>/home/ubuntu/.ssh/authorized_keys
cat /home/ubuntu/.ssh/authorized_keys >/root/.ssh/authorized_keys
chmod 644 /root/.ssh/authorized_keys
使用ubuntu的私钥就可以登陆了
也可以把/etc/ssh/下的key复制粘贴过来
/etc/ssh/ssh_host_dsa_key
/etc/ssh/ssh_host_ecdsa_key
/etc/ssh/ssh_host_ed25519_key
/etc/ssh/ssh_host_rsa_key
重启远程机
就可以直接用root登陆了
使用密码
ssh [email protected]
或者使用密钥
ssh -i ssh_host_dsa_key root@ip
ssh -i ssh_host_ecdsa_key root@ip
ssh -i ssh_host_ed25519_key root@ip
ssh -i ssh_host_rsa_key root@ip
ssh -i ssh_host_rsa1_key root@ip
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |