{"id":1068,"date":"2009-02-19T23:18:06","date_gmt":"2009-02-20T03:18:06","guid":{"rendered":"http:\/\/blogs.sungeek.net\/unixwiz\/?p=1068"},"modified":"2009-02-19T23:18:06","modified_gmt":"2009-02-20T03:18:06","slug":"ultra-restricted-shell-in-solaris","status":"publish","type":"post","link":"https:\/\/blogs.sungeek.net\/unixwiz\/2009\/02\/19\/ultra-restricted-shell-in-solaris\/","title":{"rendered":"Ultra Restricted Shell in Solaris"},"content":{"rendered":"<p>How to setup a readonly environment on Solaris:<\/p>\n<p>If you want to give a specific user readonly access to your solaris machine via ssh, and want to log everything they do, it is sort of easy to setup. Here is a quick step-by-step guide to setting it up.<\/p>\n<p>1. First you will need to chose what restricted shell you want to use. In this case I used bash as I wanted the .bash_history file to contain the exact time every command was run on the system. Since Solaris does not come with the rbash command, the only thing you need to do is make a copy of \/usr\/bin\/bash to \/usr\/bin\/rbash. <\/p>\n<p>2. Make the user&#8217;s shell be \/usr\/bin\/rbash, this will make them use the restricted bash shell. <\/p>\n<p>3. Make their home directory owned by root. <\/p>\n<p>4. Make their .profile owned by root<\/p>\n<p>5. Create a .bash_history file and make it owned by that user. This should be the only file in their directory that is owned by the user. <\/p>\n<p>6. Pick a location for your &#8220;restricted&#8221; binaries to reside. If this user will be logging in to multiple machines and you have a shared file system (say \/home) I would suggest making the directory in \/home; say \/home\/rbin.. This way you only have to put \/home\/rbin in their PATH.<\/p>\n<p>7. Make symbolic links in your restricted binary directory to the binaries you want to run. I.e. ls, ps, more, prstat,passwd and hostname :<br \/>\n<code lang=\"bash\"><br \/>\nlrwxrwxrwx   1 root     root          17 Feb 19 20:47 hostname -> \/usr\/bin\/hostname*<br \/>\nlrwxrwxrwx   1 root     root          11 Feb 19 19:56 ls -> \/usr\/bin\/ls*<br \/>\nlrwxrwxrwx   1 root     root          13 Feb 19 19:57 more -> \/usr\/bin\/more*<br \/>\nlrwxrwxrwx   1 root     root          15 Feb 19 19:56 prstat -> \/usr\/bin\/prstat*<br \/>\nlrwxrwxrwx   1 root     root          11 Feb 19 19:56 ps -> \/usr\/bin\/ps*<br \/>\nlrwxrwxrwx   1 root     root          11 Feb 19 19:56 passwd -> \/usr\/bin\/passwd*<br \/>\n<\/code><\/p>\n<p>By making these sym links instead of the actual binaries, you do not have to worry if you have multiple platforms that you are going between (i.e. Sparc, x86) and doing custom logic to use the right binary.<\/p>\n<p>8. Create the users .profile with the following in it:<br \/>\n<code lang=\"bash\"><br \/>\nreadonly PATH=\/home\/rbin<br \/>\nreadonly TMOUT=900<br \/>\nreadonly EXTENDED_HISTORY=ON<br \/>\nreadonly HOSTNAME=\"`hostname`\"<br \/>\nreadonly export HISTTIMEFORMAT=\"%F %T \"<br \/>\nreadonly export PS1='${HOSTNAME}:${PWD}> '<br \/>\n<\/code><\/p>\n<p>This will make it so they can not change any of the Environment variables. It sets their path to \/home\/rbin. Sets a inactivity time out to be 15 minutes. Sets the extended history to be on (this logs the time each command was executed in their .bash_history file). And finally sets their prompt and makes it readonly as well.<\/p>\n<p>9. The last thing you need to do is change the permissions on the scp and sftp-server binaries so that the user can not execute them. Otherwise, they would be able to download files and go any where on the server they want. (Restricted shell will prevent them from cd&#8217;ing out of their home directory) To do this, I created a group and put my user in it as their primary group. Say the group was called rdonly. Now I do the following:<\/p>\n<p><code lang=\"bash\"><br \/>\nsetfacl -m group:rdonly:--- \/usr\/lib\/ssh\/sftp-server<br \/>\nsetfacl -m group:rdonly:--- \/usr\/bin\/scp<br \/>\n<\/code><\/p>\n<p>So the files should show up like this now:<br \/>\n<code lang=\"bash\"><br \/>\nbash-3.00# ls -la \/usr\/lib\/ssh\/sftp-server \/usr\/bin\/scp<br \/>\n-r-xr-xr-x+  1 root     bin        40484 Jan 22  2005 \/usr\/bin\/scp<br \/>\n-r-xr-xr-x+  1 root     bin        35376 Jan 22  2005 \/usr\/lib\/ssh\/sftp-server<br \/>\n<\/code><\/p>\n<p>And the getfacl will look like this:<\/p>\n<p><code lang=\"bash\"><br \/>\nbash-3.00# getfacl \/usr\/bin\/scp<\/p>\n<p># file: \/usr\/bin\/scp<br \/>\n# owner: root<br \/>\n# group: bin<br \/>\nuser::r-x<br \/>\ngroup::r-x              #effective:r-x<br \/>\ngroup:rdonly:---           #effective:---<br \/>\nmask:r-x<br \/>\nother:r-x<br \/>\n<\/code><\/p>\n<p>This makes it so when the user tries to sftp or scp in to the machine, it will immediately disconnect them as they don&#8217;t have permissions to run those 2 executables.<\/p>\n<p>That is about it. Don&#8217;t forget to set their password, make sure it has a policy set on it to be changed often and require a combination of letters, numbers and special characters and that it is at least 8 characters in length.<\/p>\n<p>So now when the user logs in they will see something similar to this:<br \/>\n<code lang=\"bash\"><br \/>\n[laptop:~] unixwiz% ssh unixwiz@fozzy<br \/>\nPassword:<br \/>\nLast login: Thu Feb 19 22:10:15 2009 from laptop<br \/>\nfozzy:\/home\/unixwiz> cd \/<br \/>\n-rbash: cd: restricted<br \/>\nfozzy:\/home\/unixwiz> vi \/tmp\/test<br \/>\n-rbash: vi: command not found<br \/>\nfozzy:\/home\/unixwiz> PATH=$PATH:\/usr\/bin<br \/>\n-rbash: PATH: readonly variable<br \/>\nfozzy:\/home\/unixwiz> timed out waiting for input: auto-logout<br \/>\n<\/code><\/p>\n<p>As you can see, it will give you errors if you try to do something that you are not allowed to do. The last line shows the time out message where it closes the connection due to inactivity.<\/p>\n<p>Now if the administrator goes and looks at the users .bash_history file they would see this:<br \/>\n<code lang=\"bash\"><br \/>\n#1235099570<br \/>\ncd \/<br \/>\n#1235099577<br \/>\nvi \/tmp\/test<br \/>\n#1235099587<br \/>\nPATH=$PATH:\/usr\/bin<br \/>\n<\/code><\/p>\n<p>The #number is the exact time that the user ran the command below it. The item is the seconds since the epoch&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to setup a readonly environment on Solaris: If you want to give a specific user readonly access to your solaris machine via ssh, and want to log everything they do, it is sort of easy to setup. Here is a quick step-by-step guide to setting it up. 1. First you will need to chose &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blogs.sungeek.net\/unixwiz\/2009\/02\/19\/ultra-restricted-shell-in-solaris\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Ultra Restricted Shell in Solaris&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,2,41],"tags":[520,108,107,486,444,483],"class_list":["post-1068","post","type-post","status-publish","format-standard","hentry","category-security","category-solaris","category-tips","tag-howto","tag-rbash","tag-readonly-shell","tag-security","tag-solaris","tag-tips"],"_links":{"self":[{"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/posts\/1068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/comments?post=1068"}],"version-history":[{"count":1,"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/posts\/1068\/revisions"}],"predecessor-version":[{"id":1069,"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/posts\/1068\/revisions\/1069"}],"wp:attachment":[{"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/media?parent=1068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/categories?post=1068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sungeek.net\/unixwiz\/wp-json\/wp\/v2\/tags?post=1068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}